我想将表单数据发送到电子邮件

时间:2014-02-02 20:01:34

标签: php

我无法将表单数据发送到电子邮件(我不是PHP专家)

if(isset($_POST['submit'])){
    if(!($_POST['company'] && $_POST['email'] && $_POST['comment'])){
        echo "<font color='red'>Please insert all Fields</font>";
    }
    else{
        $recipient  = "blah@gmail.com";
        $mail_to = "oyon.ctg@gmail.com";
        $subject = "Contact Mail";
        $message = "
            Name\n
            $_POST[company]\n
            Email Address\n
            $_POST[email]\n
            Comment\n
            $_POST[comment]\n
            ";
        $email_from = "$_POST[email]";
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($mail_to,$subject,$message,$headers);

    }

1 个答案:

答案 0 :(得分:0)

<?
    if(isset($_POST['submit'])) {
        if(!isset($_POST['company']) && !isset($_POST['email']) && !isset($_POST['comment'])) {
            echo "<font color='red'>Please insert all Fields</font>";
        } else {
            $recipient = "blah@gmail.com";
            $mail_to = "oyon.ctg@gmail.com";
            $subject = "Contact Mail";
            $message = " Name\n ".$_POST['company']."\n Email Address\n ."$_POST['email']."\n Comment\n ".$_POST['comment']."\n ";
            $email_from = $_POST['email'];
        }
    }

    mail($mail_to, $subject, $message, $headers);
?>