我使用此代码通过SMTP发送邮件并出现以下错误:
问题是什么?
我的IMAP已启用,用户名和密码正确,应用程序访问gmail已开启
<?php
include 'Mail.php';
include 'Mail/mime.php' ;
$from = "Robert Davis <mymail@gmail.com>";
$to = "Sam Hill <receiver>";
$subject = 'Test mime message with an attachment';
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$text = 'Text version of email';// text and html versions of email.
$html = '<html><body>HTML version of email. <strong>This should be bold</strong></body> </html>';
$file = './sample.txt'; // attachment
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');
//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);
$host = "smtp.gmail.com";
$username = "mymail";
$password = "mypass";
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true 'username' => $username,'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
}
?>
这是我看到的错误:
身份验证失败[SMTP:从服务器收到无效的响应代码(代码:534,响应:5.7.14请通过Web浏览器登录,然后再使用5.7.14再试一次.5.7.14了解详情,请点击5.7.14 {{ 3}} x67sm2291331iod.22 - gsmtp)]