Phpmailer using Gmail to send a mail connection SMTP server error

Source: Internet
Author: User
Tags nginx server gmail password

Phpmailer version used: 5.2.1

The following are some of the code given in the example folder of Phpmailer: test_gamil_basic.php.

The code is as follows
$mail = new Phpmailer ();


$body = file_get_contents (' contents.html '); $body = $_post[' body '];


$body = Eregi_replace ("[]", ", $body);


$mail->issmtp (); Telling the class to use SMTP


$mail->smtpdebug = 2; Enables SMTP debug information (for testing)


//1 = errors and Messages


//2 = messages only


$mail->smtpauth = true; Enable SMTP authentication


$mail->smtpsecure = "SSL"; Sets the prefix to the Servier


$mail->host = "smtp.gmail.com"; Sets GMAIL as the SMTP server or ssl://smtp.gmail.com


$mail->port = 465; Set the SMTP port for the GMAIL server


$mail->username = "yourusername@gmail.com"; GMAIL username


$mail->password = "YourPassword"; GMAIL Password


$mail->setfrom (' name@yourdomain.com ', ' the ' last ');


$mail->addreplyto ("name@yourdomain.com", "the Last");


$mail->subject = "Phpmailer Test Subject via SMTP (Gmail), basic";


$mail->altbody = "To view", please use an HTML compatible email viewer! "; Optional, comment out and test


$mail->msghtml ($body);


$address = "whoto@otherdomain.com";


$mail->addaddress ($address, "John Doe");


$mail->addattachment ("Images/phpmailer.gif"); Attachment


$mail->addattachment ("Images/phpmailer_mini.gif"); Attachment


if (! $mail->send ()) {


echo "Mailer Error:". $mail->errorinfo;


} else {


echo "Message sent!";


    }

According to the code given in this example, I encountered the following error:

Www.111cn.net prompts you for SMTP error could not connect to SMTP host!

The error prompted Google to find that it is necessary to open the PHP OpenSSL extension:

Extension=php_openssl.dll//Remove the front semicolon and restart the Apache or Nginx server.

Hoho~ successfully sent.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.