php自动回复电子邮件到我的联系表格

时间:2014-12-28 08:34:14

标签: php

我已经有一个联系表格,我想向已经填写并发送表格的人添加一条自动回复信息我可以这样做:(

$mail_sent = false;

if ( ! empty($_POST) && $_POST["first_name"] != "" )
{

    // receiving a submission
    $to = $_POST['department'];
    // prep our data from the form info
    $senderName = $_POST['first_name'];
    $senderEmail = $_POST['email'];
    $department = $_POST['department'];

    $company = $_POST['company'];
    $street = $_POST['street'];
    $zip = $_POST['zip'];
    $country = $_POST['country'];
    $subjects = $_POST['subjects'];

    $subject = "Message from Webpage Contact Form";

    $messageBody = $senderName . '' . PHP_EOL . 'E-mail: ' . $senderEmail . '' . PHP_EOL . 'Company: ' . $company . '' . PHP_EOL . 'Street:
    ' . $street . '' . PHP_EOL . 'Zip: ' . $zip . '' . PHP_EOL . 'Country:
    ' . $country . '' . PHP_EOL . 'Subcject: ' . $subjects . '' . PHP_EOL . 'Comments: ' . $_POST['comments'];

    if ( $department == 'customer' )
    {
        $to = 'mail0';
    }
    else 
        if ( $department == 'distribution' )
        {
            $to = 'mail1';
        }
        else 
            if ( $department == 'press' )
            {
                $to = 'mail2';
            }
            else 
                if ( $department == 'career' )
                {
                    $to = 'mail3';
                }
                else 
                    if ( $department == 'other' )
                    {
                        $to = 'mail4';
                    }

    $send_contact = mail($to, $subject, $messageBody, $header);

    if ( $send_contact )
    {
        header('Location: #');
    }
    else
    {
        echo "ERROR";
    }
}

1 个答案:

答案 0 :(得分:0)

在这里:

 $send_contact = mail($to, $subject, $messageBody, $header);

变量$header未定义,因此不会发送邮件。

或者:

      $send_contact = mail($to, $subject, $messageBody);

或:

      $header = "From: " . $senderEmail . "\r\n";
      $send_contact = mail($to, $subject, $messageBody, $header);