PHPMailer不工作:无法发送消息
我正在尝试使用PHPMailer在我的网站上创建一个联系人表单。我在设置它时遇到了一些问题。我正在尝试使用G-mail作为smtp主机。我想知道是否有人能帮我解决这个问题 这是我的邮件代码:PHPMailer不工作:无法发送消息,php,smtp,phpmailer,contact-form,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; // tu
<?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";
?>
你看过并尝试过这个问题的信息吗 特别是,这是否提供了任何其他信息
$mail->SMTPDebug = 1;
smtp.gmail.com要求您使用SSL和端口587或465
查看他们的配置页面:您是否在Windows上运行PHP?那么这可能会有帮助:
收到了相同的错误,问题是我试图从“”发送电子邮件boy333@in**“帐户假装为”girl333@in**". 我刚换了衣服
$mail->From = 'girl333@in**'
到我实际连接的用户名。因此,我改为:
$mail->From = 'boy333@in**'
其思想是这两个字段具有相同的用户名
$mail->Username = "boy333";
$mail->From = 'boy333@in**';
转到google设置并启用“不太安全”的应用程序。这对我有用
ping smtp.gmail.com
出于某种原因,谷歌将SMTP请求重定向到gmail-SMTP-msa.l.google.com
PING gmail-smtp-msa.l.google.com (74.125.133.108): 56 data bytes
64 bytes from 74.125.133.108: icmp_seq=0 ttl=43 time=72.636 ms
64 bytes from 74.125.133.108: icmp_seq=1 ttl=43 time=68.841 ms
64 bytes from 74.125.133.108: icmp_seq=2 ttl=43 time=68.500 ms
因此,您应该将最终目的地放在配置中,因为PHPMailer不遵循重定向。此外,您还可以尝试在不使用SMTPSecure的情况下发送电子邮件,方法是将该字段保留为空
$mail->Host = 'gmail-smtp-msa.l.google.com';
$mail->SMTPAuth = true;
$mail->Username = 'email';
$mail->Password = 'password';
$mail->SMTPSecure = '';
$mail->Port = 25;
如果您的电子邮件在gsuite中,请检查两个步骤: Php邮件设置; PHP编译器版本5.2.22 检查class.phpmailer.php
var $Host = 'smtp.gmail.com';
var $Port = 465;
var $Helo ='domain.net';
public $SMTPSecure = 'ssl';
public $SMTPAutoTLS = true;
public $SMTPAuth = true;
public $SMTPOptions = array();
public $Username = 'gmail-username';//or domain credentials on google mail
public $Password = 'gmail-password';
public $Timeout = 10;
public $SMTPDebug = true;
邮件发送php
<?php
require('PHPMailer/class.phpmailer.php');
require('PHPMailer/class.smtp.php');
$headers = "Content-Type: text/html; charset=UTF-8";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="SET NAMES UTF8";
$mail->SMTPDebug = 0;
$mail->CharSet="utf8";
$mail->Debugoutput = 'html';
$mail->host = "smtp.gmail.com";
$mail->port = 465;
$mail->smtpauth = true;
$mail->smtpsecure = 'ssl';
$mail->username = "gmail-username"; //or domain credentials on google mail
$mail->password = "gmail-password";
$mail->SetFrom('from-email', 'from-name');
$mail->AddAddress('to-address', 'to-address');
$mail->Body = 'your-text'; //emailbody
if(!$mail->Send())
{
mysql_close();
echo "<script>alert('Error: " . $mail->ErrorInfo."');</script>";
}
else
{
mysql_close();
echo "<script>alert('success');</script>";
}
?>
很难说为什么它不起作用。您是否尝试过$mail->SMTPDebug=1代码>是的,我有。这是它显示的错误:SMTP->错误:无法连接到服务器:找不到套接字传输“ssl”-配置PHP时是否忘记启用它?(12640394)感谢您的回复,dubugging肯定帮了一些忙。这是smtp调试代码添加到屏幕的错误:smtp->错误:无法连接到服务器:找不到套接字传输“ssl”-配置PHP时是否忘记启用它?(12640394)根据另一个问题,听起来您必须启用extension=php_openssl.dll。另外,请看类似的问题/答案,谢谢您的回答,我尝试了这个,但没有解决问题。
var $Host = 'smtp.gmail.com';
var $Port = 465;
var $Helo ='domain.net';
public $SMTPSecure = 'ssl';
public $SMTPAutoTLS = true;
public $SMTPAuth = true;
public $SMTPOptions = array();
public $Username = 'gmail-username';//or domain credentials on google mail
public $Password = 'gmail-password';
public $Timeout = 10;
public $SMTPDebug = true;
<?php
require('PHPMailer/class.phpmailer.php');
require('PHPMailer/class.smtp.php');
$headers = "Content-Type: text/html; charset=UTF-8";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="SET NAMES UTF8";
$mail->SMTPDebug = 0;
$mail->CharSet="utf8";
$mail->Debugoutput = 'html';
$mail->host = "smtp.gmail.com";
$mail->port = 465;
$mail->smtpauth = true;
$mail->smtpsecure = 'ssl';
$mail->username = "gmail-username"; //or domain credentials on google mail
$mail->password = "gmail-password";
$mail->SetFrom('from-email', 'from-name');
$mail->AddAddress('to-address', 'to-address');
$mail->Body = 'your-text'; //emailbody
if(!$mail->Send())
{
mysql_close();
echo "<script>alert('Error: " . $mail->ErrorInfo."');</script>";
}
else
{
mysql_close();
echo "<script>alert('success');</script>";
}
?>