Php sends emails via phpmailer

Source: Internet
Author: User
Phpmailer is a powerful Mail sending class written in php. it can be used to send mails more conveniently and send attachments and HTML emails, you can also use the SMTP server to send emails. Phpmailer is a powerful Mail sending class written in php. it can be used to send mails more conveniently and send attachments and HTML emails, you can also use the SMTP server to send emails.

Although php has a mail () function, this mail function still has many limits in use and is rarely used in practical applications.

Phpmailer class File: Batch.

Example:


 CharSet = 'utf-8'; // tell the class to use SMTP $ mail-> IsSMTP (); // enable SMTP authentication $ mail-> SMTPAuth = true; // set the SMTP server port $ mail-> Port = 465; // SMTP server $ mail-> Host = "smtp.163.com "; // SMTP server username $ mail-> Username = "example@163.com"; // SMTP server password $ mail-> Password = "password "; // tell the class to use Sendmail $ mail-> IsSendmail (); // Set the sender's email address and user name $ mail-> From = "Example@163.com"; $ mail-> FromName = "username"; // Set the email address $ mail-> AddReplyTo ("example@163.com "); // Set the recipient address $ mail-> AddAddress ('example @ gmail.com '); // mail Title $ mail-> Subject = "PHP sends an email via phpmailer "; // optional, comment out and test $ mail-> AltBody = "To view the message, please use an HTML compatible email viewer! "; // Set word wrap $ mail-> WordWrap = 80; $ content = 'php sends emails via phpmailer '; $ mail-> MsgHTML ($ content ); // send as HTML $ mail-> IsHTML (true); $ mail-> Send (); echo 'Message has been sent. ';} catch (phpmailerException $ e) {echo $ e-> errorMessage ();}

The above is a simple example of phpmailer. phpmailer has many other functions that need to be studied.

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.