Sunday 15 April 2012

email - PHP MAILER GMAIL SMTP ERROR -



email - PHP MAILER GMAIL SMTP ERROR -

i in testing mode project , have setup phpmailer (ver 5.2.9) library , generate e-mails using gmail smtp.

i have setup script on local scheme when script executed keeps waiting localhost respond though have specified smtp server address.

i using following:

php version 5.4.7 xampp version 1.8.1 (it's dated, know) phpmailer version - 5.2.9

below script:

require 'phpmailer/phpmailerautoload.php'; $mail = new phpmailer; $mail->smtpdebug = 3; $mail->issmtp(); $mail->host = 'smtp.gmail.com'; $mail->smtpauth = true; $mail->username = 'xxxx@gmail.com'; $mail->password = 'xxx'; $mail->smtpsecure = 'tls'; $mail->port = 587; $mail->from = 'xxx@gmail.com'; $mail->fromname = 'test'; $mail->addaddress('xxx@outlook.com'); $mail->wordwrap = 50; $mail->ishtml(true); $mail->subject = 'here subject'; $mail->body = 'this html message body <b>in bold!</b>'; $mail->altbody = 'this body in plain text non-html mail service clients'; if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error: ' . $mail->errorinfo; } else { echo 'message has been sent'; }

thanks

your code should :

require 'phpmailer/phpmailerautoload.php'; $mail = new phpmailer; //tell phpmailer utilize smtp $mail->issmtp(); //enable smtp debugging // 0 = off (for production use) // 1 = client messages // 2 = client , server messages $mail->smtpdebug = 2; //ask html-friendly debug output $mail->debugoutput = 'html'; //set hostname of mail service server $mail->host = 'smtp.gmail.com'; //set smtp port number - 587 authenticated tls, a.k.a. rfc4409 smtp submission $mail->port = 587; $mail->smtpsecure = 'tls'; $mail->smtpauth = true; $mail->username = "username@gmail.com"; $mail->password = "yourpassword"; //set message sent $mail->setfrom('from@example.com', 'first last'); $mail->addreplyto('replyto@example.com', 'first last'); $mail->addaddress('whoto@example.com', 'john doe'); $mail->wordwrap = 50; $mail->ishtml(true); $mail->subject = 'here subject'; $mail->body = 'this html message body <b>in bold!</b>'; $mail->altbody = 'this body in plain text non-html mail service clients'; if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error: ' . $mail->errorinfo; } else { echo 'message has been sent'; }

there no alternative $mail->smtpdebug = 3;

php email smtp phpmailer

No comments:

Post a Comment