我创建了一个php脚本(用于联系表单),以便将电子邮件发送到我的Gmail帐户
如果我在标题中使用发件人电子邮件( $ headers ="来自:"。$ email; ),Gmail会将收到的邮件报告为垃圾邮件。
如果我不在标题中使用该电子邮件(例如发件人姓名 $ headers ="来自:"。$ name; ),则该邮件不会被报告为垃圾邮件。
您是否有任何建议让我在标题中使用该电子邮件?
谢谢!
<?php
/* Check if the url field is empty (antispam) */
if ($_POST['leaveblank'] != '' or $_POST['dontchange'] != 'http://') {
$name = $_POST['name'];
$faillink = "xxx.php";
header("Location: $faillink");
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$subject_prefix = "[ContactForm]: ";
$subject = $subject_prefix . $_POST['subject'];
$message = $_POST['message'];
$to = "myemail@gmail.com";
$body = "From: " . $name . "\n";
$body .= "Email: " . $email . "\n";
$body .= "Message: " . $message . "\n";
$headers = "From: " . $email;
$oklink = "yyy.php";
$faillink = "xxx.php";
if ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {
header("Location: $faillink");
}
$retmail = mail($to, $subject, $body, $headers);
if ($retmail) {
header("Location: $oklink");
} else {
header("Location: $faillink");
}
}
?>
答案 0 :(得分:2)
我解决了Iain建议的问题所以我更换了邮件标题如下:
$headers = "From: " . "noreplay@mydomain.com" . "\r\n";
$headres .= "Reply-To: " . $email . "\r\n";