Phpmailer email sending instance code

Source: Internet
Author: User
Phpmailer sends mail instance code header (& quot; Content-type: texthtml; charsetutf-8 & quot;); include (& amp; 39; phpmailerclassphpmailerphp & amp; 39;); include

Phpmailer email sending instance code

  1. Header ("Content-type: text/html; charset = utf-8 ");
  2. Include ('phpmailer/class. phpmailer. php ');
  3. Include ('phpmailer/class. smtp. php ');
  4. $ Mail = new PHPMailer ();
  5. $ Mail-> IsSMTP (); // set mailer to use SMTP
  6. $ Mail-> Host = "smtp.sohu.com"; // SMTP server
  7. $ Mail-> Port = 25;
  8. $ Mail-> SMTPAuth = true; // SMTP Authentication?
  9. $ Mail-> Username = "yourmail@sohu.com"; // User name
  10. $ Mail-> Password = "yourmail168"; // Password
  11. $ Mail-> From = "spr_zsql@163.com"; // sender address
  12. $ Mail-> FromName = "test"; // sender
  13. $ Mail-> AddAddress ("yourmail@qq.com", "test"); // recipient address, recipient name
  14. $ Mail-> WordWrap = 50;
  15. // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // attachment
  16. // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg"); // attachment, new file name
  17. $ Mail-> IsHTML (true); // HTML format
  18. $ Mail-> Subject = "test ";
  19. $ Mail-> Body = "test ";
  20. If (! $ Mail-> Send ())
  21. {
  22. Echo "Mailer Error:". $ mail-> ErrorInfo;
  23. Echo "an error occurred while sending the email! ";
  24. } Else {
  25. Echo "email sent successfully! ";
  26. }

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.