PHPmailer不会向我的Gmail帐户发送电子邮件

时间:2013-12-03 21:14:54

标签: php email

我正在使用此代码尝试让PHPmailer向使用我网站的人发送电子邮件,因为gmail显然已阻止我使用php mail()。但是,它返回错误Mailer Error: SMTP Error: The following recipients failed: myemail@gmail.com

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'myhost';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'site email';                            // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'site email';
$mail->addAddress('myemail@gmail.com');               // Name is optional

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

邮件($ to,$ subject,$ message,$ headers,“ - fSENDEREMAILID”);

尝试在邮件功能中的发件人电子邮件ID之前添加-f,它可以正常工作