本文介绍了使用PHPMailer的PHP中的SMTP验证问题,使用Pear Mail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问题在于,使用PHPMailer类发送电子邮件,但是它与PEAR Mail :: factory一起工作。 SMTP验证,但我找不到问题。
有问题的代码是:
<?php
require(class.phpmailer.php);
$ mail = new PHPMailer();
$ mail-> IsSMTP(); //设置邮件程序使用SMTP
$ mail-> Host ='mail.xxx.com.br'; //我的主机这里
$ mail-> SMTPAuth = true; //打开SMTP验证
$ mail-> Username ='[email protected]'; //这里有一封电子邮件
$ mail-> Password ='***'; //电子邮件密码
$ mail-> From ='[email protected]';
$ mail-> SMTPDebug = true;
$ mail-> AddReplyTo('[email protected]','Test');
$ mail-> FromName ='测试SMTP';
$ mail-> AddAddress('[email protected]','[email protected]');
$ mail-> Subject ='测试SMTP';
$ mail-> IsHTML(true);
$ mail-> Body ='< b> Teste< / b>< br>< h1> teste 2< / h1>
// $ mail-> Send();
if(!$ mail-> Send())
{
echo无法发送消息< p>;
echoMailer Error:。 $ MAIL-> ERRORINFO;
退出;
}
?>
PEAR的代码有效:
<?php
include('Mail.php');
include('Mail / mime.php');
$ text ='Versao em texto';
$ html ='< html>< body> Versao de email em< b> HTML< / b>< / body>< / html>';
$ crlf =\\\
;
$ hdrs = array(
'From'=>'[email protected]',
'Subject'=>'Test - mail.php'
);
$ mime = new Mail_mime($ crlf);
$ mime-> setTXTBody($ text);
$ mime-> setHTMLBody($ html);
$ body = $ mime-> get();
$ hdrs = $ mime->标头($ hdrs);
$ mail = Mail :: factory('smtp',
array('host'=>'mail.xxx.com.br',
'debug'= > true,
'auth'=> true,
'username'=>'[email protected]',
'password'=>'*** ));
$ mail-> send('[email protected]',$ hdrs,$ body);
?>
当我运行带有调试问题的代码(SMTPDebug = True)时,我得到:
SMTP - > FROM SERVER:
SMTP - > get_lines():$ data was
SMTP - > get_lines():$ str is220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
SMTP - > get_lines():$ data is220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
SMTP - > get_lines():$ data was220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
SMTP - > ; get_lines():$ str是220 - 我们不授权使用此系统来运输未经请求的
SMTP - > get_lines():$ data is220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
220 - 我们不授权使用的系统运输未经请求,
SMTP - > get_lines():$ data was220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
220 - 我们不授权使用的系统运输未经请求,
SMTP - > get_lines():$ str是220和/或批量电子邮件
SMTP - > get_lines():$ data is220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
220 - 我们不授权使用该系统运送未经请求的
220和/或批量电子邮件
SMTP - > FROM SERVER:
220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
220 - 我们不授权使用此系统运输未经请求的
220和/或批量电子邮件。
SMTP - >错误:EHLO不接受服务器:220-orion.bommtempo.net.br ESMTP Exim 4.69#1 Wed,05 Aug 2009 10:00:48 -0300
220 - 我们不授权使用的系统运输未经请求,
220和/或批量电子邮件。
SMTP - > get_lines():$ data was
SMTP - > get_lines():$ str是250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
SMTP - > get_lines():$ data is250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
SMTP - > get_lines():$ data was250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
SMTP - > get_lines():$ str是250-SIZE 20971520
SMTP - > get_lines():$ data is250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
SMTP - > get_lines():$ data was250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
SMTP - > get_lines():$ str是250-PIPELINING
SMTP - > get_lines():$ data is250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
SMTP - > get_lines():$ data was250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
SMTP - > get_lines():$ str是250-AUTH PLAIN LOGIN
SMTP - > get_lines():$ data is250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
SMTP - > get_lines():$ data was250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
SMTP - > get_lines():$ str是250-STARTTLS
SMTP - > get_lines():$ data is250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN登录
250-STARTTLS
SMTP - > get_lines():$ data was250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN登录
250-STARTTLS
SMTP - > get_lines():$ str是250 HELP
SMTP - > get_lines():$ data is250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN登录
250-STARTTLS
250帮助
SMTP - > FROM SERVER:
250-orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN登录
250-STARTTLS
250帮助
SMTP - > get_lines():$ data was
SMTP - > get_lines():$ str是250 orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
SMTP - > get_lines():$ data is250 orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
SMTP - >错误:AUTH不接受从服务器:250 orion.bommtempo.net.br你好admin-teste.bommtempo.com.br [200.155.129.6]
SMTP - > get_lines():$ data was
SMTP - > get_lines():$ str是没有广告时使用的503 AUTH命令
SMTP - > get_lines():$ data is503 AUTH command not not advertiseed
SMTP - > FROM SERVER:
503未通知时使用的AUTH命令
SMTP - >错误:RSET失败:503 AUTH命令用于不通告
无法发送消息。 < p> Mailer错误:SMTP错误:无法连接到SMTP主机。
PEAR邮件代码的调试结果为:
调试:Recv:220-orion.bommtempo.net.br ESMTP Exim 4.69#1星期二,2009年8月04日19: 37:10 -0300
DEBUG:Recv:220 - 我们不授权使用此系统来运输未经请求的
DEBUG:Recv:220和/或bulk e -邮件。
DEBUG:发送:EHLO本地主机
DEBUG:Recv:250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG:Recv:250-SIZE 20971520
DEBUG:Recv:250-PIPELINING
DEBUG:Recv:250-AUTH PLAIN LOGIN
DEBUG:Recv:250-STARTTLS
DEBUG:Recv:250 HELP
DEBUG:发送:STARTTLS
DEBUG: Recv:220 TLS go ahead
DEBUG:发送:EHLO localhost
DEBUG:Recv:250-orion.bommtempo.net.br Hello localhost [200.155。 129.6]
DEBUG:Recv:250-SIZE 20971520
DEBUG:Recv:250-PIPELINING
DEBUG:Recv:250-AUTH PLAIN LOGIN
DEBUG:Recv:250 HELP
DEBUG:发送:AUTH LOGIN
DEBUG:Recv:334 VXNlcm5hbWU6
DEBUG:发送:c2lzdGVtYWFkbWluQGJvbW10ZW1wby5jb20uYnI =
DEBUG:Recv:334 UGFzc3dvcmQ6
DEBUG:发送:RVkyYVM4YnpMNU5k
DEBUG:Recv:235认证成功
DEBU G:发送:MAIL FROM:
调试:Recv:250 OK
调试:发送:RCPT TO:
DEBUG:Recv:250 Accepted
DEBUG:发送:DATA
DEBUG:Recv:354输入消息,以。结尾。一行一行
DEBUG:发送:MIME版本:1.0
发件人:[email protected]
主题:Teste de mail - mail.php
内容类型:multipart / alternative;
boundary == _ b3c5407ccf494306d78fbb35800efe65
- = _ b3c5407ccf494306d78fbb35800efe65
内容转移编码:7bit
内容-Type:text / plain; charset =ISO-8859-1
Versao em texto
- = _ b3c5407ccf494306d78fbb35800efe65
内容转移编码: quoted-printable
内容类型:text / html; charset =ISO-8859-1
Versao de email em HTML - = _ b3c5407ccf494306d78fbb35800efe65--
。
DEBUG:Recv:250 OK id = 1MYSd4-0005Ky-Jw
DEBUG:发送:QUIT
解决方案
奇怪的问题,我通过评论这行解决
// $ MAIL-> IsSmtp();
最后一个phpmailer版本(5.2)
I´m having trouble sending a e-mail with the PHPMailer class, but it works with PEAR Mail::factory.
I guess the problem is with the SMTP authentication, but I couldn´t find the problem.
The code with problem is:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = 'mail.xxx.com.br'; // my host here
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = '[email protected]'; // a valid email here
$mail->Password = '***'; // the password from email
$mail->From = '[email protected]';
$mail->SMTPDebug = true;
$mail->AddReplyTo('[email protected]', 'Test');
$mail->FromName = 'Test SMTP';
$mail->AddAddress('[email protected]', '[email protected]');
$mail->Subject = 'Test SMTP';
$mail->IsHTML(true);
$mail->Body = '<b>Teste</b><br><h1>teste 2</h1>';
//$mail->Send();
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
?>
The code with PEAR that works is:
<?php
include('Mail.php');
include('Mail/mime.php');
$text = 'Versao em texto';
$html = '<html><body>Versao de email em <b>HTML</b></body></html>';
$crlf = "\n";
$hdrs = array(
'From' => '[email protected]',
'Subject' => 'Test - mail.php'
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail = Mail::factory('smtp',
array ('host' => 'mail.xxx.com.br',
'debug'=> true,
'auth' => true,
'username' => '[email protected]',
'password' => '***'));
$mail->send('[email protected]', $hdrs, $body);
?>
When I run the code with problem with debug activated (SMTPDebug = True) I got:
SMTP -> FROM SERVER:
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $str is "220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $str is "220 and/or bulk e-mail.
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
"
SMTP -> FROM SERVER:
220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
SMTP -> ERROR: EHLO not accepted from server: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $str is "250-SIZE 20971520
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
"
SMTP -> get_lines(): $str is "250-PIPELINING
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
"
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $str is "250-STARTTLS
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $str is "250 HELP
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
"
SMTP -> FROM SERVER:
250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> ERROR: AUTH not accepted from server: 250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "503 AUTH command used when not advertised
"
SMTP -> get_lines(): $data is "503 AUTH command used when not advertised
"
SMTP -> FROM SERVER:
503 AUTH command used when not advertised
SMTP -> ERROR: RSET failed: 503 AUTH command used when not advertised
Message could not be sent. <p>Mailer Error: SMTP Error: Could not connect to SMTP host.
And the debug result of the PEAR Mail code is:
DEBUG: Recv: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Tue, 04 Aug 2009 19:37:10 -0300
DEBUG: Recv: 220-We do not authorize the use of this system to transport unsolicited,
DEBUG: Recv: 220 and/or bulk e-mail.
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG: Recv: 250-SIZE 20971520
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250-STARTTLS
DEBUG: Recv: 250 HELP
DEBUG: Send: STARTTLS
DEBUG: Recv: 220 TLS go ahead
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG: Recv: 250-SIZE 20971520
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250 HELP
DEBUG: Send: AUTH LOGIN
DEBUG: Recv: 334 VXNlcm5hbWU6
DEBUG: Send: c2lzdGVtYWFkbWluQGJvbW10ZW1wby5jb20uYnI=
DEBUG: Recv: 334 UGFzc3dvcmQ6
DEBUG: Send: RVkyYVM4YnpMNU5k
DEBUG: Recv: 235 Authentication succeeded
DEBUG: Send: MAIL FROM:
DEBUG: Recv: 250 OK
DEBUG: Send: RCPT TO:
DEBUG: Recv: 250 Accepted
DEBUG: Send: DATA
DEBUG: Recv: 354 Enter message, ending with "." on a line by itself
DEBUG: Send: MIME-Version: 1.0
From: [email protected]
Subject: Teste de mail - mail.php
Content-Type: multipart/alternative;
boundary="=_b3c5407ccf494306d78fbb35800efe65"
--=_b3c5407ccf494306d78fbb35800efe65
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
Versao em texto
--=_b3c5407ccf494306d78fbb35800efe65
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="ISO-8859-1"
Versao de email em HTML--=_b3c5407ccf494306d78fbb35800efe65--
.
DEBUG: Recv: 250 OK id=1MYSd4-0005Ky-Jw
DEBUG: Send: QUIT
解决方案
strange issue that i solved by comment this line
//$mail->IsSmtp();
whit the last phpmailer version (5.2)
这篇关于使用PHPMailer的PHP中的SMTP验证问题,使用Pear Mail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!