PHPMailer无法正常工作:无法发送消息 [英] PHPMailer not working: Message could not be sent

查看:187
本文介绍了PHPMailer无法正常工作:无法发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a contact form on my website using PHPMailer. I am having some trouble setting it up. I am trying to use G-mail as my smtp host. I was wondering if anyone can help troubleshoot this?

这是我的邮递区号:

<?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

推荐答案

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

Have you looked at and tried the info from this Q?

PHPMailer:SMTP错误:无法连接到SMTP主机

特别是,这是否提供任何其他信息?

In particular, does this provide any additional info?

$mail->SMTPDebug = 1;

这篇关于PHPMailer无法正常工作:无法发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆