2017-12-27 1 views
-1

제 코드를 변경했지만 효과가 없습니다. 코드 자체는 오류를 반환하지 않고 대신 성공 메시지를 제공합니다. 내 릴레이로 Gmail을 사용하고 있습니다.phpmailer 6.0 성공 메시지하지만 메일을 릴레이로 사용하여 메일을 수신하지 못했습니다.

P.S, 수정본으로 사용한 것과 비슷한 질문을했기 때문에 $mail->IsSMTP();을 주석 처리했습니다. "연결에 실패했습니다"라는 오류가 발생했습니다.

저는 PHPmailer 6.0을 사용하고 있습니다.

2017-12-27 07:58:54 Connection: opening to smtp.gmail.com:465, timeout=300, options=array() 2017-12-27 07:58:54 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:465 (Network is unreachable) [/srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/SMTP.php line 325] 2017-12-27 07:58:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

치명적인 오류 : catch되지 않은 PHPMailer \ PHPMailer \ 예외 : 나는 $mail->IsSMTP(); 내가이 오류 로그를 얻을 주석을 제거하면

<?php 
 

 
    require_once('vendor/autoload.php'); 
 

 
    define('GUSER', '[email protected]'); // GMail username 
 
    define('GPWD', '*********'); // GMail password 
 

 
    function smtpmailer($to, $from, $from_name, $subject, $body) { 
 
\t global $error; 
 
\t $mail = new PHPMailer\PHPMailer\PHPMailer(true); // create a new object 
 
\t //$mail->IsSMTP(); // enable SMTP 
 
\t $mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only 
 
\t $mail->SMTPAuth = true; // authentication enabled 
 
\t $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail 
 
\t $mail->Host = 'smtp.gmail.com'; 
 
\t $mail->Port = 465; 
 
\t $mail->Username = GUSER; 
 
\t $mail->Password = GPWD; 
 
\t $mail->SetFrom($from, $from_name); 
 
\t $mail->Subject = $subject; 
 
\t $mail->Body = $body; 
 
\t $mail->AddAddress($to); 
 
\t if(!$mail->Send()) { 
 
\t \t $error = 'Mail error: '.$mail->ErrorInfo; 
 
\t \t return false; 
 
\t } else { 
 
\t \t $error = 'Message sent!'; 
 
\t \t return true; 
 
\t } 
 
    } 
 

 
    smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail message', 'Hello World!'); 
 
    if (smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail message', 'Hello World!')) { 
 
\t // do something 
 
    } 
 
    if (!empty($error)) echo $error; 
 

 
?>

: 여기

내 코드는 SMTP 연결 실패. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php:1726 스택 추적 : # 0 /srv/disk2/2564570/www/consorttest.dx.am/ PHPMailer \ PHPMailer \ PHPMailer-> smtpSend ('Date : Wed, 27 D ...', 'Hello World! \ r \ n') # 1/srv /disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1320) : PHPMailer \ PHPMailer \ PHPMailer-> postSend() # 2/srv/disk2/2564570/www/consorttest .dx.am/mailtest.php (23) : PHPMailer \ PHPMailer \ PHPMailer-> send() # 3 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(32) : smtpmailer ('to @mail.com ',' [email protected] ','yourName ','test mail messa ... ','Hello World! ') # 4 {main}/srv/disk2/2564570/www/consorttest .dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1726

답변

0

0을 주석 처리하면 "릴레이를 사용하여 Gmail"이 아닙니다.입니다. SMTP를 전혀 사용하지 않기 때문에 모든 SMTP 설정이 무시됩니다. PHP의 내장 된 mail 기능을 사용하여 로컬 메일 서버를 통해 전송합니다.

gmail을 통해 보낼 때 gmail 계정에 별칭을 미리 설정할 수 있지만 임의의 주소를 사용할 수는 없습니다.

PHPMailer와 함께 제공되는 gmail을 사용하여 매우 오래된 구식 예제에 코드를 기반으로합니다.

오류 출력의 가장 중요한 부분은 다음과 같습니다. Network is unreachable - ISP가 아웃 바운드 SMTP를 차단했음을 의미합니다. GoDaddy를 사용하고 있습니까?

다음으로 기본 구성 오류가 있습니다. SMTPSecure = 'tls'을 사용하여 포트 465에 연결합니다. 즉, SMTP + STARTTLS 명시 적 TLS 암호화를 사용하려고 시도하지만 포트 465에서는 작동하지 않습니다. 이것은 다음과 같습니다. 제공된 예제를 사용하는 주요 이유 - 이런 기본적인 오류를 만들지 않습니다.

이 모든 것들은 the troubleshooting guide에 오류가 있습니다.

관련 문제