无法理解为什么我得到这个错误 – 无论是从邮件地址是有效的(我每天都在使用它们),所以无法弄清楚这是怎么发生的 – 任何帮助,将不胜感激。
注:这是在生产中工作,但是在dev中抛出错误。 我有更严格的configuration在开发。 注意:我正在使用smtp4dev在PC上进行本地testing
$to = 'recipient <[email protected]>'; $cc = 'copy <[email protected]>'; $from = 'sender <[email protected]>'; $filename = 'Invoice#'.$order_id.'.pdf'; $message = file_get_contents(ROOT_DIR.'admin/include/email-body.html'); $content = chunk_split(base64_encode($pdf_file)); $uid = md5(uniqid(time())); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'To: '. $to . "\r\n"; $headers .= 'Cc: '. $cc . "\r\n"; $headers .= 'From: '. $from . "\r\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $headers .= "This is a multi-part message in MIME format.\r\n"; $headers .= "--".$uid."\r\n"; $headers .= "Content-type:text/html; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $headers .= $message."\r\n\r\n"; $headers .= "--".$uid."\r\n"; $headers .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $headers .= $content."\r\n\r\n"; $headers .= "--".$uid."--"; if (mail($to, $subject, $message, $headers)) { print "SUCCESS"; } else { print "FALIED"; }
如果我在mail()行打印variables,结果如下:
mail(recipient <[email protected]>, Company - Invoice#12451, "", MIME-Version: 1.0 To: recipient <[email protected]> Cc: copy <[email protected]> From: sender <[email protected]> Content-Type: multipart/mixed; boundary="2c88ff549e67c83e7a6e3df0bffe9dc9" This is a multi-part message in MIME format. --2c88ff549e67c83e7a6e3df0bffe9dc9 Content-type:text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit ---> html message body stripped <--- --2c88ff549e67c83e7a6e3df0bffe9dc9 Content-Type: application/pdf; name="Invoice#12451.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Invoice#12451.pdf" --> pdf attachment stripped <-- --2c88ff549e67c83e7a6e3df0bffe9dc9--)
你的$必须只是邮件地址。 SMTP对话框需要使用尖括号中的邮件地址,并将To:标题的内容提供给它。 $也是一样的。