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.