我是来自西澳大利亚珀斯Fijura Web Design的Beau。
我的服务器出现问题。我正在尝试创建一个脚本,该脚本将发送带有附件的电子邮件,每当我尝试运行该脚本时,我都会收到以下响应:
警告:邮件()[function.mail]:SMTP服务器响应:552 5.7.0数据标头大小超过E:\folder\folder\api\sendreports.php中允许的最大值在线52
我使用的代码是一个经过验证的脚本,因为我在数据中心的共享Linux服务器上使用它,但我无法在Windows服务器上使用。我使用的脚本是:
include "../reports/rankings.php"; //this is my FPDF attachment
$to=$array['email']; //this pulls an email address from an array output by my MySQL Server
$from="Fijura SEO<seo@fijura.com.au>";
$subject="SEO Ranking Report - New Data ".date("d M Y");
$message="New SEO data is available. See attached report.";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "SEO-Ranking-Report-".date("d-M-Y").".pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; //If I remove all $header information from this line down the email sends fine, just without the attachment.
$headers .= "Content-Type: multipart/mixed; boundary="".$separator.""".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset="iso-8859-1"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name="".$filename.""".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
mail($to,$subject,$message,$headers) or die("Failed");
所附的PDF应该是这样的:示例SEO排名报告
php.ini文件配置如下:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.bigpond.com
; http://php.net/smtp-port
smtp_port = 25
我想你的电子邮件会回来的。我有3个建议:1.仔细阅读Spamhaus项目,它会导致你的电子邮件不是垃圾邮件。2.创建一个*.eml并通过socket发送。你的.eml包含你的电子邮件,如标题、正文、附件等。3.不要使用php语言的mail()函数,因为一些共享主机禁止它。