简体   繁体   English

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

[英]php Auto-reply email to my contact form

I Already have a contact form and I want to add an auto reply message to the person who already filled and sent the form HOW CAN I DO THIS:( 我已经有联系表格,我想向已经填写并发送表格的人添加自动回复消息,我该怎么做:(

$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";
    }
}

In here: 在这里:

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

variable $header is undefined and thus no mail will be send. 变量$header是未定义的,因此不会发送任何邮件。

Either: 或者:

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

or: 要么:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM