我正在使用PHPMailer发送电子邮件。在我的一个页面上,邮件脚本在页面显示之前运行。邮件被发送,它也显示在页面内容上方的屏幕上。为什么呢?
<?php
/* many things */
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail-> Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "donotreply@example.com";
$mail->Password = "password";
$mail->SetFrom('donotreply@example.com', 'Example Support');
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
//$mail->WordWrap = 70;
$mail->Send();
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!--many things-->
</html>
使用php的mail()函数我从未遇到过这个问题:
mail($email,$subject,$message,$headers);