我在使用 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 收件人数组,但是这些收件人没有收到任何电子邮件。