我使用 Pear 将我们网站的一个用户(“发件人”)电子邮件中继给另一个用户(“收件人”)失败,因为收件人用户总是在他们的垃圾邮件文件夹中收到邮件。对于以下解释,我们的网站称为“oursite.com”。
在对“标题”的“发件人”部分进行了 2 天的大量实验后,我已经缩小了范围,如下所示(为了这个例子,我的名字是Sam Hambone,我不知道“发件人:”在电子邮件的标题中是抓住我的名字并使用它,如下所述):
$senderEmail = "IamTheSender@gmail.com";
// this version of the 'from' variable makes the 'From' in the email's title
// look correct, like this: "IamTheSender@gmail.com (IamTheSender@gmail.com)"
// but when the recipient gets the mail, it will ALWAYS go into the 'junk'
// or 'spam' email folder of the recipient's inbox. NOTE: using angle brackets
// instead of parentheses here changes nothing.
$from = $senderEmail . " (" . $senderEmail . ")";
// this second version of 'from' makes the mail arrive correctly
// in the recipient's Inbox and not in their spam/junk folder, but
// the "From:" line in the email's title looks like this:
// "Sam Hambone (IamTheSender@gmail.com)"
$from = $senderEmail;
编辑:这是使用上面第一个版本的“发件人”的电子邮件标题和标题的样子——在这种情况下,我作为收件人向自己发送了一封电子邮件:
'Sender has a question for you, Mr. Recipient!'
Sam Hambone (IamTheSender@gmail.com) << this is wrong -- it's mixing my (recipient)
real name with the sender's email address!!
To: sammyhambone@hotmail.com
From: IamTheSender@gmail.com
Sent: Fri 10/18/13 5:49 PM
To: sammyhambone@hotmail.com (sammyhambone@hotmail.com)
这是其余的代码 - 此代码成功发送了电子邮件,但是通过使用上述版本的from变量之一,我发现电子邮件转到收件人的垃圾文件夹或“发件人:”部分如上所述,电子邮件的标题搞砸了:
$theRecipient = "aLoyalUser@hotmail.com";
$to = $theRecipient . " (" . $theRecipient . ")";
$subject = "the subject is Pear and emailing.";
$body = "Ach, megotts lads, comes the blarney stone."
$host = "smtp.1and1.com";
$port = "25";
$username = "myAuthName@oursite.com";
$password = "12345";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$headers['From'] = $from; // one of the two 'from' versions given above
$headers['To'] = $to;
$headers['Subject'] = $subject;
$mail = $smtp->send($theRecipient, $headers, $body);
// tried this, no help
$mail = $smtp->send($to, $headers, $body);
我需要将发件人的电子邮件信息发送到收件人的收件箱,但电子邮件标题的“发件人:”部分不得显示“Sam Hambone (IamTheSender@gmail.com)”。
这里缺少什么?