PHPMailer未发送邮件

PHPMailer未发送邮件,php,email,smtp,Php,Email,Smtp,伙计们,我已经读了很多关于这个问题的答案,但问题仍然存在。 PHPMailer未发送包含以下错误的电子邮件 邮件程序错误:SMTP连接()失败 代码如下: date_default_timezone_set('Etc/UTC'); require 'PHPMailer-master/PHPMailerAutoload.php'; //Create a new PHPMailer instance $mail = new PHPMailer; //Tell PHPMailer to use S

伙计们,我已经读了很多关于这个问题的答案,但问题仍然存在。 PHPMailer未发送包含以下错误的电子邮件

邮件程序错误:SMTP连接()失败

代码如下:

date_default_timezone_set('Etc/UTC');

require 'PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.domain.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port =25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
//Username to use for SMTP authentication
$mail->Username = "mail@mail.com";
//Password to use for SMTP authentication
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom("mail@mail.com","Contact Form");
//Set an alternative reply-to address
$mail->addReplyTo($_POST['user_mail'], $_POST['user_name']);
//Set who the message is to be sent to
$mail->addAddress("mail@mail.com", "Contact Form");
//Set the subject line
$mail->Subject = $_POST['subject'] . " - Contact Form";
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("Message from ". $_POST['user_name']." : <br/>".$_POST['message'] . "<br/> Contact Details : <br/> Email :" . $_POST['user_mail'] . "<br/> Contact Number : " . $_POST['user_number']);
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "<script>window.location.href='thankyou.html';</script>";
}
date\u default\u timezone\u set('Etc/UTC');
需要“PHPMailer master/phpmailerautoad.php”;
//创建新的PHPMailer实例
$mail=新的PHPMailer;
//告诉PHPMailer使用SMTP
$mail->isSMTP();
//启用SMTP调试
//0=关闭(用于生产使用)
//1=客户端消息
//2=客户端和服务器消息
$mail->SMTPDebug=0;
//请求HTML友好的调试输出
//$mail->Debugoutput='html';
//设置邮件服务器的主机名
$mail->Host=“mail.domain.com”;
//设置SMTP端口号-可能是25、465或587
$mail->Port=25;
//是否使用SMTP身份验证
$mail->SMTPAuth=true;
$mail->SMTPSecure=“tls”;
//用于SMTP身份验证的用户名
$mail->Username=”mail@mail.com";
//用于SMTP身份验证的密码
$mail->Password=“Password”;
//设置要从谁发送消息
$mail->setFrom(“mail@mail.com“,”联系方式“);
//将替代答复设置为地址
$mail->addReplyTo($\u POST['user\u mail'],$\u POST['user\u name']);
//设置要向谁发送邮件
$mail->addAddress(“mail@mail.com“,”联系方式“);
//设置主题行
$mail->Subject=$\u POST['Subject']。“-联系方式”;
//从外部文件读取HTML消息正文,将引用的图像转换为嵌入的,
//将HTML转换为基本的纯文本替换体
$mail->msgHTML(“来自“$\u POST['user\u name']”的邮件:
“$\u POST['Message']”,
联系详细信息:
电子邮件:“$\u POST['user\u mail']”,
联系电话:“$\u POST['user\u Number']”); //将纯文本正文替换为手动创建的正文 //$mail->AltBody='这是一个纯文本消息正文'; //附加图像文件 //$mail->addAttachment('images/phpmailer_mini.png'); //发送消息,检查错误 如果(!$mail->send()){ 回显“邮件错误:”.$mail->ErrorInfo; }否则{ echo“window.location.href='thankyou.html';”; }
设置此
$mail->SMTPDebug=0
2
,并向我们显示更详细的错误。但该错误意味着它无法连接到smtp服务器。该错误表明它无法连接到smtp服务器。您是否使用公共SMTP服务器(如gmail)?你确定你的用户名和密码(以及端口)正确吗?@hungrykoala出于安全风险,我是否应该删除该错误中的一些数据,将其发布到此处?如果SMTP端口号不工作,请在服务器设置SMTP_server=SMTP.gmail.com中配置sendmail.php文件,smtp_ssl=auto,并设置auth_用户名和auth_password@SONGSTER请这样做。另外,这是错误
无效地址
密码命令失败