Phpmailer can send emails with attachments

Source: Internet
Author: User

Instance require_once ('phpmailer/class. phpmailer. php '); // introduce the phpmailer file require_once ('phpmailer/class. smtp. php '); $ mail = new PHPMailer (); // instantiate the phpmailer class $ mail-> IsSMTP (); $ mail-> CharSet = 'utf-8 '; $ mail-> AddAddress (123@163.com); // recipient email $ mail-> Body = $ content; // sender content $ mail-> From = from@163.com; // sender email from@163.com $ mail-> FromName = "zjsupport"; // sender's name $ mail-> Subject = "title "; // mail title $ mail-> Host = "smtp.163.com"; // smtp server $ mail-> SMTPAuth = true; // enable the smtp service $ mail-> IsHTML (true ); // send the attachment $ mail-> AddAttachment (path, name); // path indicates the Save path of the attachment. name indicates the name of the attachment. // you can upload multiple attachments, exactly copy $ mail-> AddAttachment (path, name); Code on the line $ mail-> Username = "from@163.com"; // sender mailbox $ mail-> Password = "123456 "; // sender's email password if ($ mail-> Send () {// determines whether the email is successfully sent echo "success";} else {$ email_error = $ email_error. ";". $ val; // if the email address fails to be sent, the email address will be saved to the string.} if ($ email_error = "") {echo "email_success" ;}else {echo $ email_error ;}

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.