添加电子邮件和发件人 - PHP表单

时间:2017-08-02 08:08:16

标签: php email

我有联系表格。我想将CC添加到电子邮件:abc@abc.de并更改电子邮件发件人。目前它显示我的服务器作为发件人,我想要回复表单用户。

您好。 我有联系表格。我想将CC添加到电子邮件:abc@abc.de并更改电子邮件发件人。目前它显示我的服务器作为发件人,我想要回复表单用户。

<?php 
    session_start();
    //Ajax Questions Form 
    if(isset($_POST['email'])){

        $name = $_POST['name'];
        $email = $_POST['email'];
        $arrival = $_POST['arrival'];
        $departure = $_POST['departure'];
      ///   $adults = $_POST['adults'];
      //    $children = $_POST['children'];
     // $room = $_POST['room'];
        $requests = $_POST['requests'];
        $to = 'contact@test.camp'; //Replace with recipient email address

        $subject = 'Hotel Booking'; //Subject line for emails
        $message = 'From: '.$name."\r\n".'Email: '.$email."\r\n".'Arrival: '.$arrival."\r\n".'People: '.$departure; //."\r\n".'Adults: '.$adults."\r\n".'Children: '.$children."\r\n".'Room: '.$room."\r\n".'Requests: '.$requests;
        // Mail Functions 
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
            mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.

            echo "Your email was sent!"; // success message
        }


    }

    //Contact Php Form 
    if(isset($_POST['contact_email'])){

        $contact_name = $_POST['contact_name'];
        $email = $_POST['contact_email'];
        $contact_message = $_POST['message'];
        $to = 'marek@gmail.com'; //Replace with recipient email address
        $subject = 'Contact Form'; //Subject line for emails
        $message = 'From: '.$contact_name."\r\n".'Email: '.$email."\r\n".'Message: '.$contact_message;
        // Mail Functions 
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // This line checks that we have a valid email address
            mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.


        }

    }





?>

2 个答案:

答案 0 :(得分:1)

php邮件功能没有太多功能尝试使用PHPMailer之类的东西,它允许你发送更复杂的电子邮件

答案 1 :(得分:0)

要添加CC或BCC或ReplyTo,请在您的电子邮件结构中添加标题:

$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

$headers[] = 'To: andreas<mail1@gmail.com>, thomas<mail2@gmail.com>';
$headers[] = 'From: from <from@gmail.com>\r\nReply-to: <ReplyTo@gmail.com>';
$headers[] = 'Cc: Cc@gmail.com';
$headers[] = 'Bcc: Bcc@gmail.com';

mail($to, $subject, $message, implode("\r\n", $headers));