PHP email sending (126 mail and PHPMailer open-source)

Source: Internet
Author: User
Tags php email
PHP mail (126 mailbox and PHPMailer open source) I. first download PHPMailer

Https://github.com/chenlian2015/phpmailer.git


2. Download

Class. phpmailer. php

Class. smtp. php

Copy two files to your project directory.


III. use

 CharSet = "GBK"; // Set the mail encoding, the default ISO-8859-1, this must be set if you send Chinese, otherwise garbled $ mail-> IsSMTP (); // Set the SMTP Service $ mail-> SMTPDebug = 1; // enable SMTP debugging // 1 = errors and messages // 2 = messages only $ mail-> SMTPAuth = true; // enable the SMTP authentication function // $ mail-> SMTPSecure = "ssl"; // security protocol. you can comment out $ mail-> Host = 'smtp .126.com '; // SMTP server $ mail-> Port = 25; // SMTP server Port $ mail-> Username = 'write your 126 mailbox here '; // SMTP server user name, PS: I am playing $ mail-> Password = 'here Write your password '; // SMTP server password $ mail-> SetFrom ('write your 126 mailbox here', 'who '); $ mail-> AddReplyTo ('write the destination email here ', 'name'); $ mail-> Subject = $ subject; $ mail-> AltBody = 'To view the message, please use an HTML compatible email viewer! '; // Optional, comment out and test $ mail-> MsgHTML ($ body); $ address = $ to; $ mail-> AddAddress ($ address ,''); $ mail-> AddAttachment ("windowsment"); // attachment // $ mail-> AddAttachment ("images/phpmailer_mini.gif"); // attachment if (! $ Mail-> Send () {echo 'mailer Error: '. $ mail-> ErrorInfo;} else {echo "Message sent! Congratulations, the email is sent successfully! ";}} Postmail ('write the target email here ', 'My subobject', 'Hang LA');?>
Related Article

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.