2009-08-05 4 views
16

PHPMailer 클래스를 사용하여 전자 메일을 보내는 데 문제가 있지만 PEAR Mail :: factory와 함께 작동합니다.PHP에서 메일 인증을 사용하여 PHP 메일을 사용할 때 문제가 발생합니다.

SMTP 인증에 문제가있는 것 같지만 문제를 찾을 수 없습니다.

문제가있는 코드는 다음과 같습니다 작동 PEAR와

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

?> 

코드는 다음과 같습니다

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

내가있어 (SMTPDebug = 참) 활성화 디버그와 문제로 코드를 실행하면 :

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. 

차 배 메일 코드의 디버그 결과는 다음과 같습니다

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 

답변

0

에는 OpenSSL 확장을 사용할 수 있고 "BR"와 디렉토리 언어? 은 먼저 데이터를 확인합니다.

+0

근무 phpinfo() 내가 가진 : ... OpenSSL 지원 \t 사용 OpenSSL 버전 \t OpenSSL 0.9.8e-fips-rhel5 2008 년 7 월 1 일 PEAR을 사용하면 그게 효과가 있습니다. – Evandro

16

보십시오이 추가 :

(..snip..) 
SMTP -> ERROR: AUTH not accepted from server: 250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 
(..snip..) 
503 AUTH command used when not advertised 
(..snip..) 

성공적인 PEAR 로그이 표시하는 동안 : 디버그 로그를 살펴보면

$mail->SMTPAuth = true; 
$mail->SMTPSecure = "tls"; 

을, 당신은 실패 PhpMailer 로그이 표시되는지 알 수

DEBUG: Send: STARTTLS 
DEBUG: Recv: 220 TLS go ahead 

내 생각에 PHPMailer에 TLS를 사용하도록 명시 적으로 요청하면 오른쪽 trac에 넣을 것입니다 케이.
또한 PHPMailer의 최신 버전을 사용하고 있는지 확인하십시오.

+1

이 대답은 내 문제를 해결했습니다. 저의 호스팅 회사는 SSL을하지 말라고 말했지만, TLS가 필요하다고 생각하고 저에게 말하지 않았습니다 : p – Sebas

0

Exim 4는 클라이언트가 EHLO를 발급 한 후에 만 ​​AUTH 명령을 보내도록 요구합니다. EHLO없이 인증을 시도하면 거부됩니다. 일부 메일 서버는 EHLO를 두 번 발행해야합니다. PHPMailer는 분명히 그렇게하지 못합니다. PHPMailer가 EHLO 초기화를 강제로 허용하지 않으면 실제로는 SwiftMailer 4으로 전환해야합니다. 내가 코멘트에 의해이 라인

//$mail->IsSmtp(); 

를 해결

+0

PHPMailer는 자동으로 올바른 일을하고 STARTTLS 후에 EHLO를 다시 보냅니다. – Synchro

38

이상한 문제는 마지막 phpmailer 버전 (5.2) 만 일부 시스템 사용자에게 보내는 SMTP (루트, MTA 제한 설정 한 경우

+1

라인을 주석 처리하면 전자 메일을 보낸 것처럼 출력을 생성하지만 실제로 그러한 전자 메일은 보내지지 않습니다. –

+0

나를 위해서는 아니지만 이상하게 들리지만이 코드는 프로덕션 환경에 있고 모든 이메일이 전송됩니다 ... (내 phpmailer는 1 살입니다) – maurox

+1

이것은 주석 행이 다음과 같은 경우에 발생합니다 : 인스턴스를 생성 할 수 없습니다. 메일 기능. 메일러 오류 : 메일 기능을 인스턴스화 할 수 없습니다. – a77icu5

0

확인 엉 우편 집배원...). 이 제한은 스팸 발송자를 차단할 수 있지만 보내는 SMTP 연결을 로컬 메일 서버로 리디렉션합니다.

2

이것은 나에게도 일어난 일입니다. 필자의 경우, Postfix는 PHP 스크립트와 동일한 서버에 있었고 localhost 대신 SMTP 인증 및 smtp.domain.com을 사용할 때 오류가 발생했습니다.

그래서 나는이 라인에서 주석 때

$ 메일 -> SMTPAuth = TRUE;
$ mail-> SMTPSecure = "tls";

$mail->Host = "localhost"; 

대신

$ 메일 -> 호스트 = 'smtp.mydomainiuse.com'

에 호스트를 설정하고 그것을에서 :)

관련 문제