我遇到了php的邮件功能问题。
这是代码:
public function send_email($emailInfo)
{
// email fields: to, from, subject, and so on
$to = $emailInfo['toEmail'];
$from = $emailInfo['fromEmail'];
$subject = $emailInfo['subject'];
$message = $emailInfo['message'];
//$message = $this->base_directory.'/application/views/emailtemplates/ticketresponse'($emailInfo['viewVars'], true);
$headers = 'From: '.$emailInfo['fromEmail'].' <'.$emailInfo['fromEmail'].'>';
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
if (is_array($emailInfo['cc']))
{
$headers .= 'Cc: ';
foreach ($emailInfo['cc'] as $cc)
{
$headers .= $cc. ",";
}
$headers = substr($headers, 0, -1);
$headers .= "\r\n";
}
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// send
@mail($to, $subject, $message, $headers, '-f'.$emailInfo['fromEmail']);
}
该功能确实发送了电子邮件,确实填充了cc收件人数组,但这些收件人不会收到任何电子邮件。
答案 0 :(得分:0)
提供的任何其他标头必须由\r\n
分隔,即CRLF
。您正在为cc标头执行此操作,但不会为其他标头执行此操作。这可能会产生影响。
$headers .= "\nMIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"{$mime_boundary}\"\r\n";
答案 1 :(得分:0)
我强烈建议避免使用PHP的内置mail()
功能。除了最基本的恐慌电子邮件之外,它真的不适合用于网站管理员的任何目的。
除此之外(包括添加CC地址之类的简单内容),我建议使用一个像样的邮件程序类,例如PHPMailer。它将使您的代码更多更简单,更可靠。
希望有所帮助。