Phpmailer send examples of gmail emails _php tips

Source: Internet
Author: User
Tags gmail password
Copy Code code as follows:

&LT;TITLE&GT;PHPMAILER-SMTP (Gmail) Basic test</title>
<body>
<?php
Error_reporting (E_all);
Error_reporting (e_strict);
Date_default_timezone_set (' America/toronto ');
Require_once ('.. /class.phpmailer.php ');
Include ("class.smtp.php"); Optional, gets called from within class.phpmailer.php if not already loaded
$mail = new Phpmailer ();
$body = file_get_contents (' contents.html ');
$body = eregi_replace ("[\]", ", $body);
$mail->issmtp (); Telling the class to use SMTP
$mail->host = "mail.gmail.com"; SMTP Server
$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
$mail->port = 465; Set the SMTP port for the GMAIL server
$mail->username = "* * * @gmail. com"; GMAIL username
$mail->password = "* * *"; GMAIL Password
$mail->setfrom (' * * * @gmail. com ', ' the ' last ');
$mail->addreplyto ("* * @gmail. com", "the Last");
$mail->subject = "Phpmailer Test Subject via SMTP (Gmail), basic";
$mail->altbody = "To view", compatible email viewer! with an HTML; Optional, comment out and test
$mail->msghtml ($body);
$address = "* * * @gmail. 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!";
}
?>
</body>

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.