0
votes

I would like to send an email using Gmail SMTP server through PHP Mailer.

I am running Zend Server Community Edition in my machine.

Following is my code (edited to hide certain confidential information).

 require_once('phpmailer/class.phpmailer.php');

        $mail             = new PHPMailer();

        $body             = "test msg";

        $mail->IsSMTP();
        $mail->SMTPDebug  = 2;                    

        $mail->SMTPAuth   = true;                  
        $mail->SMTPSecure = "tls";                 
        $mail->Host       = "smtp.gmail.com";      
        $mail->Port       = "587";                    
        $mail->Username   = "<valid-id>";  
        $mail->Password   = "<valid-password>";            

        $mail->SetFrom('[email protected]', 'Name');

        $mail->AddReplyTo("[email protected]","Name");

        $mail->Subject    = "subject";

        $mail->MsgHTML($body);

        $address = "[email protected]";
        $mail->AddAddress($address, "halo:);

        if(!$mail->Send())
        {
          echo "Mailer Error: " . $mail->ErrorInfo;
        }
        else
        {
          echo "Message sent!";
        }

Despite following thoroughly the example from PHP Mailer wiki page, I somehow couldn't manage to send the email accordingly.

This is the error message generated by the function:

SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) The following From address failed: [email protected] Mailer Error: The following From address failed: [email protected]

Please advise me regarding this matter. Thank you.

1
smtp server probably do some checks during smtp-session, for instance to fight with spam. b.c - unexisting domain, so it don't want to route mails from this domainCyberDem0n
I used the valid domain previously and it generated the same exact message.rofans91
It's not just about the domain. GMail is fierce about spam fighting. Likely, they will also check that the entire email address is valid (it exists on the domain). Try sending mail from your own domain and creating an email account like [email protected] so that other mail servers see that the From address is valid. You can set this email's quota to 0MB if you don't want it to receive any mail.Bailey Parker

1 Answers

2
votes

have you tried:

$mail->SMTPAuth   = true;                  
$mail->SMTPSecure = "ssl";                 
$mail->Host       = "smtp.gmail.com";      
$mail->Port       = "465";

I have changed in your code my emails, my smtp user, my settings ^^^, password and the line:

$mail->AddAddress($address, "Mihai"); // you forgot a quote

used PHPMailer5.2.1 and result:

SMTP -> FROM SERVER:220 mx.google.com ESMTP gq2sm2073759bkc.13 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [***.***.***.***] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES 
SMTP -> FROM SERVER:250 2.1.0 OK gq2sm2073759bkc.13 
SMTP -> FROM SERVER:250 2.1.5 OK gq2sm2073759bkc.13 
SMTP -> FROM SERVER:354 Go ahead gq2sm2073759bkc.13 
SMTP -> FROM SERVER:250 2.0.0 OK 1345113839 gq2sm2073759bkc.13 
Message sent!

Mail received:

X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/)