[英]Send email using the GMail SMTP server from a Unix weberver website using php
我正在尝试使用以下php代码发送SMTP电子邮件。
<?php
require_once "Mail.php";
$from = "info@XXXXX.com";
$to = "info@XXXXXX.com";
$subject = "Hi";
$body = "Hi,\n\nHow are you?\nDoing anything this Friday evening?\n";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "xxxxx";
$password = "xxxxx";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'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>" );
}
?>
当我从Unix Web服务器网页执行代码时。 我收到以下错误。
authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]
但是上面的代码在我的本地主机工作正常。
请帮助我完成项目。
谢谢。
我遇到了同样的问题,您应该在G-Suite中启用SMTP,更多详细信息请参见: https : //support.google.com/a/answer/2956491?hl = zh_CN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.