php mail()发送两个不同的消息提交给不同的方

时间:2016-02-17 15:29:30

标签: php email

我修改了以下脚本。一切似乎都有效,除了提交表单的人('to2')收到一封电子邮件('message2' - 带有单个空行),然后是('message' - 带有双空格行)。

('message')的收件人应该正常工作,因为他们只能获得('message' - 使用单个空格行)。

我的目标仅针对('to2')接收('message2'),而不是('message')。我尝试将邮件('message2')字符串定位在脚本逻辑的不同位置,但是,我一直得到相同的结果或破坏。任何有关逻辑的帮助都表示赞赏。

这是脚本......

<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=500">
<title>EXAMPLE</title>
</head>
<body>

<?php

if(isset($_POST['Submit'])) {
$ip_address = $_SERVER['REMOTE_ADDR'];
    $Subject = 'TEST';
    $Subject2 = 'SUCCESS';
    $A1 = $_POST['A1'];
    $Name = $_POST['Name'];
    $Phone = $_POST['Phone'];
    $Email = $_POST['Email'];
    $message = $_POST['message'];
    $message2 = $_POST['message2'];

// Type in your Email address to receive the mail
$to =  'me@example.com';
$to2 =  $Name.' <'.$Email.'>';

    if($Name == "" or $Phone == "" or $Email == "" ) {
        echo 'One or more fields has not been filled out.<br>
        Click on your browser back button once and try again.';
    }
    elseif(!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
        echo 'The Email address could not be validated.<br>
        Click on your browser back button once and verify your Email address.';
    }
    else { // All checks passed

        $headers = "From: ".$Name." <".$Email.">\r\n";
        $headers .= "Bcc: [VENDOREMAILS]\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        $headers2 = "From: Support <me@example.com>\r\n";
        $headers2 .= "MIME-Version: 1.0\r\n";
        $headers2 .= "Content-Type: text/html; charset=utf-8\r\n";
        $message = "
Subject: $Subject<br>
Question: $A1<br>
Name: $Name<br>
Phone: $Phone<br>
Email: $Email
";
        $message2 = "
Subject: $Subject2<br>
Question: $A1<br>
Name: $Name<br>
Phone: $Phone<br>
Email: $Email
"
.nl2br($message);
        $sendMail = mail($to, $Subject, $message, $headers);
        if($sendMail) {
            echo "THANK YOU FOR YOUR SUBMISSION";
            mail($to2, $Subject2, $message2, $headers2);
        }
        else {
            echo "An error occured and the mail could not be sent.<br>
Please try again";
        }
    }
}
else {
    header("location:example.html");
}    
?>

</body>
</html>

1 个答案:

答案 0 :(得分:2)

删除代码

.nl2br($message);

从$ message2的定义结束。我认为应该这样做。