gpt4 book ai didi

PHPMailer 不工作 : Message could not be sent

转载 作者:行者123 更新时间:2023-12-02 02:51:47 27 4
gpt4 key购买 nike

我正在尝试使用 PHPMailer 在我的网站上创建联系表单。我在设置时遇到一些问题。我正在尝试使用 G-mail 作为我的 smtp 主机。我想知道是否有人可以帮助解决这个问题?

这是我的邮件代码:

<?php
require("class.phpmailer.php");
require("class.smtp.php");

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 467;

$mail->Username = "validmail@gmail.com"; // SMTP username
$mail->Password = "workingpassword"; // SMTP password

$mail->From = "validmail@gmail.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@example.net", "Josh Adams");
$mail->AddAddress("ellen@example.com"); // name is optional
$mail->AddReplyTo("info@example.com", "Information");

$mail->WordWrap = 50; // set word wrap to 50 characters


// $mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
// $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$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. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

错误信息:

Message could not be sent.
Mailer Error: The following From address failed: validmail@gmail.com

最佳答案

您是否查看并尝试过此问题中的信息?

PHPMailer: SMTP Error: Could not connect to SMTP host

特别是,这是否提供了任何附加信息?

$mail->SMTPDebug = 1;

关于PHPMailer 不工作 : Message could not be sent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10981968/

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