gpt4 book ai didi

php - 从 PHP 页面使用 GMail SMTP 服务器发送电子邮件

转载 作者:IT老高 更新时间:2023-10-28 11:36:47 24 4
gpt4 key购买 nike

我正在尝试从 PHP 页面通过 GMail 的 SMTP 服务器发送电子邮件,但出现此错误:

authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: mx.google.com at your service, [98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]

有人可以帮忙吗?这是我的代码:

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <ramona@microsoft.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";

$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>");
}
?>

最佳答案

// Pear Mail Library
require_once "Mail.php";

$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}

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

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