gpt4 book ai didi

php - 使用 php 从 Unix weberver 网站使用 GMail SMTP 服务器发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:40 25 4
gpt4 key购买 nike

我正在尝试使用以下 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 网络服务器网页执行代码时。我收到以下错误。

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=en

关于php - 使用 php 从 Unix weberver 网站使用 GMail SMTP 服务器发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24452816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com