2013-09-24 2 views
0

Я пытался использовать Google как SMTP-сервер, например this, но он не может отправлять почту. Как это исправить? Кажется, что есть брандмауэр, который блокирует мой скрипт.SMTP PHPMailer не работает

<?php 
    require("PHPMailer_5.2.4/class.phpmailer.php"); 

    $mail = new PHPMailer(); 
    $mail->SMTPDebug = true; 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->SMTPAuth = true; // SMTP authentication 
    $mail->Host  = "smtp.gmail.com"; // SMTP server 
    $mail->Port  = 465; // SMTP Port 
    $mail->Username = "[email protected]"; // SMTP account username 
    $mail->Password = "xxx";  // SMTP account password 

    $mail->SetFrom('[email protected]', 'Hieutot'); // FROM 
    $mail->AddReplyTo('[email protected]', 'Hieutot'); // Reply TO 

    $mail->AddAddress('[email protected]', 'HieuND2'); // recipient email 

    $mail->Subject = "First SMTP Message"; // email subject 
    $mail->Body  = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer."; 

    if(!$mail->Send()) { 
     echo 'Message was not sent.'; 
     echo 'Mailer error: ' . $mail->ErrorInfo; 
    } else { 
     echo 'Message has been sent.'; 
    } 

Это мой журнал:

SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "" 
SMTP -> get_lines(): $data is "" 
SMTP -> get_lines(): timed-out (10 seconds) 
SMTP -> FROM SERVER: 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "" 
SMTP -> get_lines(): $data is "" 
SMTP -> FROM SERVER: 
SMTP -> ERROR: EHLO not accepted from server: 
SMTP -> FROM SERVER: 
SMTP -> ERROR: HELO not accepted from server: 
SMTP -> ERROR: AUTH not accepted from server: 
SMTP -> NOTICE: EOF caught while checking if connectedThe following From address failed: [email protected] : Called Mail() without being connected Message was not sent.Mailer error: The following From address failed: [email protected] : Called Mail() without being connected 

ответ

2

попробовать с помощью:

$mail->Host = "ssl://smtp.gmail.com"; 

вместо:

$mail->Host = "smtp.gmail.com"; 
Смежные вопросы