Example of PHP using Phpmailer to send mail

Source: Internet
Author: User
Tags word wrap
  1. Require ("phpmailer/class.phpmailer.php");
  2. function Smtp_mail ($sendto _email, $subject, $body, $extra _hdrs, $user _name) {
  3. $mail = new Phpmailer ();
  4. $mail->issmtp (); Send via SMTP
  5. $mail->host = "smtp.163.com"; SMTP servers
  6. $mail->smtpauth = true; Turn on SMTP authentication
  7. $mail->username = "xuchao842363331"; SMTP username Note: Normal mail authentication does not need to add @ domain name here is my 163 mailbox
  8. $mail->password = "Password"; SMTP Password Enter the password for the mailbox here
  9. $mail->from = "jbxue123@163.com"; Sender Mailbox
  10. $mail->fromname = "Administrator"; Sender
  11. $mail->charset = "UTF-8"; Specify the character set here! After you specify UTF-8, the title and sender of the message will not be garbled, if the GB2312 title will be garbled
  12. $mail->encoding = "base64";
  13. $mail->addaddress ($sendto _email, "username"); Recipient's mailbox and name
  14. $mail->addreplyto ("yourmail@yourdomain.com", "yourdomain.com");
  15. $mail->wordwrap = 50; Set word wrap word wrapping
  16. $mail->addattachment ("/var/tmp/file.tar.gz"); Attachment Accessories
  17. $mail->addattachment ("/tmp/image.jpg", "new.jpg");
  18. $mail->ishtml (TRUE); Send As HTML
  19. Message subject
  20. $mail->subject = $subject;
  21. Message content
  22. $mail->body = "hello! Phpmailer ";
  23. $mail->altbody = "text/html";
  24. if (! $mail->send ())
  25. {
  26. echo "Error

    ";

  27. echo "Error:". $mail->errorinfo;
  28. Exit
  29. }
  30. else {
  31. echo "success!";
  32. }
  33. }
  34. Parameter description (Sent to, message subject, message content, additional information, user name)
  35. ?>
Copy Code

Description: When the character set is specified as GB2312, the caption will be garbled, this is specified as UTF-8 does not appear garbled. In fact, Phpmailer also has many functions, such as can add attachments and so on, here is no longer demonstrated.

This allows you to call this function when you need to use the Mail function:

    1. Require ("mail.php");
    2. Smtp_mail ("790896688@qq.com", "Welcome to the programmer's house", "", "", "username");
    3. ?>
Copy Code
  • 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.