PHPMailer email sending

Source: Internet
Author: User
: This article mainly introduces PHPMailer mail sending. if you are interested in PHP tutorials, refer to it. Reference PHPMailerAutoload. php, class. phpmailer. php, class. smtp. php

Instantiate the application file index. php


// SMTP needs accurate times, and the PHP time zone MUST be set
// This shoshould be done in your php. ini, but this is how to do it if you don't have access to that
Date_default_timezone_set ('etc/UTC ');

Require './PHPMailerAutoload. php ';

// Create a new PHPMailer instance
$ Mail = new PHPMailer ();
// Tell PHPMailer to use SMTP
$ Mail-> isSMTP ();
// Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$ Mail-> SMTPDebug = 2;
// Ask for HTML-friendly debug output
$ Mail-> Debugoutput = 'html ';
// Set the hostname of the mail server
$ Mail-> Host = "smtp.qq.com ";
// Set the SMTP port number-likely to be 25,465 or 587
$ Mail-> Port = 25;
// Whether to use SMTP authentication
$ Mail-> SMTPAuth = true;
// Username to use for SMTP authentication
$ Mail-> Username = "###@ qq.com"; // sender's Email and name
// Password to use for SMTP authentication
$ Mail-> Password = "####"; // sender's Password and name
// Set who the message is to be sent from
$ Mail-> setFrom ('#### @ qq.com', 'First LA'); // sender's Email and name
// Set an alternative reply-to address
$ Mail-> addReplyTo ('###@ qq.com', 'First LA'); // sender's Email and name
// Set who the message is to be sent
$ Mail-> addAddress ('###@ qq.com', 'John Doe '); // recipient Email and name
// Set the subject line
$ Mail-> Subject = 'phpmailer SMTP test ';
// Read an HTML message body from an external file, convert referenced images to embedded,
// Convert HTML into a basic plain-text alternative body
$ Mail-> msgHTML ("adwawdawd ");
// Replace the plain text body with one created manually
$ Mail-> AltBody = 'This is a plain-text message body ';
// Attach an image file
// $ Mail-> addAttachment ('images/phpmailer_mini.png ');

// Send the message, check for errors
If (! $ Mail-> send ()){
Echo "Mailer Error:". $ mail-> ErrorInfo;
} Else {
Echo "Message sent! ";
}
?>

The sender needs to configure the qq mail server in the qq mail.

The above describes PHPMailer mail sending, including content, and hope to be helpful to friends who are interested in PHP tutorials.

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.