更改标题"From: noreply@domain.com"对于其他值,将邮件发送到垃圾邮件文件夹


Changing header "From: noreply@domain.com" to other value, sends mail into spam folder

我在我的网站上有这个php mail()代码,它工作得很好。

这是一个电子卡片系统,我的客户可以填写从信息(姓名,电子邮件)和信息(姓名,电子邮件)等,邮件直接进入收件箱,在谷歌,hotmail,雅虎等。

当收件人收到电子邮件时,他可以使用回复按钮,它会得到正确的信息。

问题是我的邮件表单中的From:标题,我想将其从noreply@example.com更改为收件人的信息,或任何其他信息。当我这样做时,邮件就会变成垃圾邮件。

下面是我使用的代码

<?php
$name = $_REQUEST['name'] ;
$motive = $_REQUEST['email'] ;
$name2 = $_REQUEST['name2'] ;
$email2 = $_REQUEST['email2'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;
$message =  urldecode(stripslashes($message));
$headers = 'From:' . $name . ' John Q<noreply@example.com>' . "'r'n";
$headers .= 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers.= "Reply-To:" .$name. "<" . $motive. ">'n";
$headers.= "Return-Path: My Company<admin@datatopixels.com>'n";
$headers.= "X-Mailer: PHP". phpversion() ."'n";

$messagee = "
<html>
<head>
<title>Title here</title>
</head>
<body>
<center>
<br>
</center>
</body>
</html>
";

mail($to, $subject, $messagee, $headers);
?>

必须添加针头:

示例代码:
$headers = "From: myplace@example.com'r'n";
$headers .= "Reply-To: myplace2@example.com'r'n";
$headers .= "Return-Path: myplace@example.com'r'n";
$headers .= "CC: sombodyelse@example.com'r'n";
$headers .= "BCC: hidden@example.com'r'n";
if ( mail($to,$subject,$message,$headers) ) {
   echo "The email has been sent!";
   } else {
   echo "The email has failed!";
   }
?> 

我建议大家读一读oswald的