【发布时间】:2011-08-21 13:29:12
【问题描述】:
我正在使用 PHP 的 mail() 函数发送电子邮件(sendmail 进程正在运行)。但是所有的邮件都会变成垃圾邮件(如果是 gmail)。我尝试了很多我在网上找到的技巧,但没有一个有效,请告诉我任何可靠的技巧。
【问题讨论】:
-
您的电子邮件是垃圾邮件吗?
-
没有..但是电子邮件进入了垃圾邮件文件夹
我正在使用 PHP 的 mail() 函数发送电子邮件(sendmail 进程正在运行)。但是所有的邮件都会变成垃圾邮件(如果是 gmail)。我尝试了很多我在网上找到的技巧,但没有一个有效,请告诉我任何可靠的技巧。
【问题讨论】:
您必须添加针头:
示例代码:
$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!";
}
?>
【讨论】:
没有确定的投篮技巧。您需要探索您的邮件被归类为垃圾邮件的原因。 SpamAssassin 有一个描述Some Tips for Legitimate Senders to Avoid False Positives 的页面。另见Coding Horror: So You'd Like to Send Some Email (Through Code)
【讨论】:
<?php
$subject = "this is a subject";
$message = "testing a message";
$headers .= "Reply-To: The Sender <sender@domain.com>\r\n";
$headers .= "Return-Path: The Sender <sender@domain.com>\r\n";
$headers .= "From: The Sender <sender@domain.com>\r\n";
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
mail("reciever@domain.com", $subject, $message, $headers);
?>
【讨论】:
$headers = "Reply-To: The Sender <sender@domain.com>\r\n";
试试PHP Mailer library。
或通过 SMTP 发送邮件在发送之前对其进行过滤。
同时尝试提供所有详细信息,例如FROM、return-path。
【讨论】:
$fromMail = 'set your from mail';
$boundary = str_replace(" ", "", date('l jS \of F Y h i s A'));
$subjectMail = "New design submitted by " . $userDisplayName;
$contentHtml = '<div>Dear Admin<br /><br />The following design is submitted by '. $userName .'.<br /><br /><a href="'.$sdLink.'"><b>Click here</b></a> to check the design.</div>';
$contentHtml .= '<div><a href="'.$imageUrl.'"><img src="'.$imageUrl.'" width="250" height="95" border="0" alt="my picture"></a></div>';
$contentHtml .= '<div>Name : '.$name.'<br />Description : '. $description .'</div>';
$headersMail = '';
$headersMail .= 'From: ' . $fromMail . "\r\n" . 'Reply-To: ' . $fromMail . "\r\n";
$headersMail .= 'Return-Path: ' . $fromMail . "\r\n";
$headersMail .= 'MIME-Version: 1.0' . "\r\n";
$headersMail .= "Content-Type: multipart/alternative; boundary = \"" . $boundary . "\"\r\n\r\n";
$headersMail .= '--' . $boundary . "\r\n";
$headersMail .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headersMail .= 'Content-Transfer-Encoding: base64' . "\r\n\r\n";
$headersMail .= rtrim(chunk_split(base64_encode($contentHtml)));
try {
if (mail($toMail, $subjectMail, "", $headersMail)) {
$status = 'success';
$msg = 'Mail sent successfully.';
} else {
$status = 'failed';
$msg = 'Unable to send mail.';
}
} catch(Exception $e) {
$msg = $e->getMessage();
}
这对我来说很好用。它包括带有图像和链接的邮件,适用于各种邮件 ID。线索是完美地使用所有标题。
如果您是从 localhost 进行测试,请在检查前设置以下内容:
如何设置从 localhost xampp 发送邮件:
评论D:/xampp/sendmail/sendmail.ini中的所有内容并在下面提及
[发送邮件]
smtp_server=smtp.gmail.com smtp_port=587 error_logfile=error.log debug_logfile=debug.log auth_username=yourmailid@domain.com auth_password=你的邮件密码 force_sender=yourmailid@domain.com
在D:/xampp/php/php.ini
一种。下
[邮件功能]
SMTP = smtp.gmail.com smtp_port = 587
b.设置sendmail_from = yourmailid@domain.com
C。取消注释 sendmail_path = "\"D:\xamp\sendmail\sendmail.exe\" -t"
因此它应该如下所示
sendmail_path = "\"D:\xamp\sendmail\sendmail.exe\" -t"
d。评论 sendmail_path="D:\xamp\mailtodisk\mailtodisk.exe" 因此它应该如下所示
;sendmail_path="D:\xamp\mailtodisk\mailtodisk.exe"
e。 mail.add_x_header=Off
【讨论】:
<?php
$to1 = 'test@gmail.com';
$subject = 'Tester subject';
// To send HTML mail, the Content-type header must be set
$headers .= "Reply-To: The Sender <sender@sender.com>\r\n";
$headers .= "Return-Path: The Sender <sender@sender.com>\r\n";
$headers .= "From: sender@sender.com" ."\r\n" .
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
?>
【讨论】: