PHP SMTP 邮件功能不适用于 phpmailer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14305440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:03:00  来源:igfitidea点击:

PHP SMTP mail function not working with phpmailer

phpsmtp

提问by logan

PHP SMTP mail function not working with phpmailer and throwing following error

PHP SMTP 邮件功能无法与 phpmailer 一起使用并抛出以下错误

Error:SMTP Error: Language string failed to load: tls.

错误:SMTP 错误:语言字符串加载失败:tls。

My Code is :

我的代码是:

require_once('class.phpmailer.php');

$mail  = new PHPMailer();   
$mail->IsSMTP();    
$mail->SMTPAuth   = True;                  // enable SMTP authentication
$mail->SMTPSecure = "tls";                 // sets the prefix to the server
$mail->Host       = "localhost";      
$mail->Port       = 25;                 
$mail->Username   = "[email protected]";  // my username
$mail->Password   = "xxxx";            // my password

$mail->From       = "[email protected]";
$mail->FromName   = "you name";
$mail->Subject    = "some subject";
$mail->MsgHTML("the message");

$mail->AddAddress("[email protected]","logan");
$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {//to see if we return a message or a value bolean
    echo "Mailer Error: " . $mail->ErrorInfo;
} else  echo "Message sent!";

I have got the host and port details my web service provider but not working.

我已经获得了我的 Web 服务提供商的主机和端口详细信息,但无法正常工作。

When i debug, following is the error:

当我调试时,以下是错误:

SMTP -> FROM SERVER:220 We do not authorize the use of this system to transport unsolicited, and/or bulk e-mail.
SMTP -> FROM SERVER: 250-mail02.clientns.net [127.0.0.1], this server offers 4 extensions 250-AUTH LOGIN 250-SIZE 52428800 250-HELP 250 AUTH=LOGIN
SMTP -> FROM SERVER:503 Bad sequence of commands
SMTP -> ERROR: STARTTLS not accepted from server: 503 Bad sequence of commands
SMTP -> FROM SERVER:250 Requested mail action okay, completed
Language string failed to load: tls Mailer Error: Language string failed to load: tls

Could any one please let me know why is it not connecting ?

任何人都可以让我知道为什么它无法连接?

回答by logan

It worked for me when i remove following..

当我删除以下内容时,它对我有用..

//$mail->SMTPSecure = "tls";

回答by Alex

You tell PHPMailler to use a secured mail service hosted on your server. If you don't know if it's the case, comment the lines as this and test it (it will use php native "mail()" function as described here):

您告诉 PHPMailler 使用托管在您服务器上的安全邮件服务。如果您不知道是否是这种情况,请按此注释行并对其进行测试(它将使用此处描述的 php 原生“mail()”函数):

require_once('class.phpmailer.php');

$mail  = new PHPMailer();   
//$mail->IsSMTP();    
//$mail->SMTPAuth   = false;                  // enable SMTP authentication
//$mail->SMTPSecure = "ssl";                 // sets the prefix to the server
//$mail->Host       = "localhost";      
//$mail->Port       = 25;                 
//$mail->Username   = "[email protected]";  // my username
//$mail->Password   = "xxxx";            // my password

$mail->From       = "[email protected]";
$mail->FromName   = "you name";
$mail->Subject    = "some subject";
$mail->MsgHTML("the message");

$mail->AddAddress("[email protected]","logan");
$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {//to see if we return a message or a value bolean
    echo "Mailer Error: " . $mail->ErrorInfo;
} else  echo "Message sent!";