我修改了以下脚本。一切似乎都正常,除了提交表单('to2')的人收到一封电子邮件,其中("message2" - 带有单空格行),后跟("消息" - 带有双倍空格行)。
("消息")的收件人正常工作,因为他们只得到("消息" - 带有单空格行)。
我的目标是('to2')只接收('消息2'),而不跟('消息')。我尝试将mail('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>
删除代码
.nl2br($message);
从 $message 2 定义的末尾开始。我认为应该这样做。