PHPMailer 不工作 : Message could not be sent

标签 php smtp phpmailer contact-form

我正在尝试使用 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/

相关文章:

PHP/mySQL 多维数组还是面向对象的方法?

php - 计算表 2 中请求表 1 的用户数

php - 如何使用分页实现同位素

php - 如何禁用 PHPMailer 中的错误消息?

php - 缺少扩展名 : openssl Message could not be sent

php - 实现 smiliar_text 或 Levenshtein 查询

php.ini & SMTP= - 你如何传递用户名和密码

c# - 使用 Socket 和 SSL 的 SMTP 连接

c# - 如何使用 System.Net.Mail 将电子邮件发送到多个地址

phpMailer:向多个收件人发送电子邮件