PHP under the use of Phpmailer

Source: Internet
Author: User
Tags openssl version account security ssl connection using git

What are the advantages of Phpmailer?

    • Can be run on top of any platform
    • Support for SMTP authentication
    • Specify multiple recipients, CC address, send address and reply address when sending mail; Note: Add cc, BCC only under the win platform SMTP mode support
    • Supports multiple message encodings including: 8bit,base64,binary and Quoted-printable
    • Support for redundant SMTP servers, that is, you can specify the primary SMTP server address and can only specify the backup SMTP server
    • Support for mail with attachments, you can add any format of attachments to the message---of course your server has enough bandwidth support
    • Custom message header information, which is similar to sending header information in PHP via the header function
    • Support to make the message body HTML content, you can insert a picture in the body of the message
    • Flexible Debug Support
    • Tested and compatible SMTP servers include: Sendmail,qmail,postfix,imail,exchange, etc.

How do I download the Phpmailer code package?

Phpmailer Project Address: Https://github.com/PHPMailer/PHPMailer clone to local using git command, or click "Download ZIP" directly at the bottom right of the project page To get to the full Phpmailer code package.

How to use Phpmailer with the "domain Mailbox" under the QQ mailbox to use your own domain name as email address to send mail?

====

The following two parts, explain the use of their own domain name free to open the "domain Mailbox" under the QQ Mailbox and PHP environment using Phpmailer and with the newly opened "Domain name mailbox" Automatically send mail.

====

The first part: opening the "domain Mailbox" under the QQ mailbox

Since the opening of the "domain Mailbox" is only an understanding of how to operate, this part is only a brief talk.

    • Enter the QQ mailbox, click on the top left of the page "settings", and then click on the "Mailbox settings" under the "Account" tab, drag the scroll bar, you can see the "Domain Mailbox", click "Manage Domain Name mailbox" To enter the domain name mailbox added pages, or directly click http://domain.mail.qq.com/
    • Click "Create a Domain name mailbox" and follow the page prompts to add your own domain name and verify it. PS: If your QQ mailbox successfully added a "Domain name mailbox", then enter the QQ mailbox, the top left of the page "settings" button will have "domain name mailbox" text
    • Add your own email address for the domain name mailbox, click "Member Management" in the "domain Mailbox" approved by the audit, click "Add Member", enter the email name under your domain name, then add QQ number (the QQ number is used as the user of the newly added mailbox. QQ is required to open the QQ mailbox and does not close the digital account number)
    • Just entered the QQ number of QQ mailbox will receive an open domain mailbox notification mail, in the mail click "Accept this mailbox account", the use of phpmailer Send mail sender email address is set to complete, in order to facilitate the description of this email address called "Sender mailbox."
    • For the QQ number of password security, please set the "Independent password" for the QQ, in the QQ mailbox "set"-"account"-"account security" to set up the password, in order to facilitate the description of this article, called "Independent password."

At this point, the "domain Mailbox" under the QQ mailbox is opened and added to the email address that will be sent as the sender using Phpmailer. Here are a few key information to be used by Phpmailer: QQ number, QQ number added in the third step above, "Independent password", "Sender Mailbox", Sender's name ...

Part II: Writing code to send mailboxes using Phpmailer

Phpmailer need PHP Socket extension support, and Phpmailer link QQ domain name mailbox need SSL encryption Method (QQ mailbox has recently limited, new open domain mailbox no longer allow 25 port through the SMTP protocol of the normal link way link, Only allow SSL 465 or 587 ports [my one domain mailbox open in the domain mailbox at present 25 port is still can link, may be security policy, limit the new open domain mailbox account 25 port]), solid PHP also have the support of OpenSSL, can view phpinfo, The following two items are available, including the OpenSSL version number and so on, many virtual host PHP is not support OpenSSL extension, then you may be tragic.

This section is for code examples only, and some comments are explained in the code.

Download the Phpmailer after decompression to thin body, only need class.phpmailer.php, class.pop3.php, class.smtp.php and phpmailerautoload.php four files, language folder can not be, that is mainly used for debug debugging display information. Look at the file size of class.phpmailer.php, 110kb, quite scary.

  1. <? PHP
  2. Introducing Phpmailer core files using require_once contains warnings to avoid duplicate definitions of Phpmailer classes
  3. Require_once("phpmailer/class.phpmailer.php");
  4. Exemplary Phpmailer Core class
  5. $mail = new Phpmailer();
  6. Whether to enable debug for SMTP debugging development environment It is recommended to turn on the production environment comment off to turn debug debug mode off by default
  7. $mail-smtpdebug = 1;
  8. Use SMTP authentication method to send mail, of course you can choose Pop mode SendMail way and so on do not explain in this article
  9. Refer to the http://phpmailer.github.io/PHPMailer/for more information
  10. $mail-issmtp();
  11. SMTP needs authentication This must be true
  12. $mail-Smtpauth=true;
  13. The server address of the link QQ domain mailbox
  14. $mail, Host = ' smtp.qq.com ';
  15. Set login authentication using SSL encryption
  16. $mail-smtpsecure = ' SSL ';
  17. To set the remote server port number for an SSL connection to an SMTP server optional 465 or 587
  18. $mailPort = 465;
  19. Set SMTP Helo message header This optional content is arbitrary
  20. $mail-Helo = ' Hello smtp.qq.com Server ';
  21. Setting the sender's host domain is optional by default to localhost content, it is recommended to use your domain name
  22. $mail-Hostname = ' jjonline.cn ';
  23. Set the encoding of sent messages optional GB2312 I like utf-8. UTF8 is said to be garbled in some client's inbox.
  24. $mail-CharSet = ' UTF-8 ';
  25. Set the sender's name (nickname) any content that displays the sender's name before the sender's e-mail address of the recipient's message
  26. $mail-fromname = ' jingjing online ';
  27. SMTP login account here to fill in the string format QQ number can be
  28. $mail-Username =' 888888 ';
  29. The password for the SMTP login is filled in with "Independent password", if the password is set "Independent password", then fill in QQ passwords recommended setting "Independent password"
  30. $mail-Password = ' xxxxxxx ';
  31. Set the sender's e-mail address here fill in the "sender's mailbox" mentioned above
  32. $mailfrom = ' [email protected] ';
  33. Whether the message body is HTML-encoded note here is a method that is no longer a property of true or False
  34. $mail-ishtml(true);
  35. To set a recipient's mailbox address this method has two parameters the first parameter is the recipient's mailbox address the second parameter is a nickname that is set to that address. The second parameter has a small meaning.
  36. $mail-addaddress(' [email protected] ',' jingjing online users ');
  37. Adding multiple recipients calls the method multiple times
  38. $mail-addaddress(' [email protected] ',' jingjing online users ');
  39. Add the subject of the message
  40. $mail-Subject = ' Phpmailer example of sending mail ';
  41. Adding ishtml to true on top of the message body can be a complete HTML string such as: Use the file_get_contents function to read the local HTML file
  42. $mailBody = "This is a <b style=\" color:red;\ ">PHPMailer</b> a test case for sending mail" ;
  43. Add an attachment to the message the method also has two parameters the first parameter is the directory where the attachment is stored (either relative to the directory, or absolute directory) The second parameter is the name of the attachment in the message attachment
  44. $mail-addattachment('./d.jpg ',' mm.jpg ');
  45. The same method can be called multiple times to upload several attachments
  46. $mail-addattachment('./jlib-1.1.0.js ',' jlib.js ');
  47. Send command returns a Boolean value
  48. PS: After testing, if the recipient does not exist, and if the error is still returned to true that is, before sending themselves need some method to detect whether the mailbox is true and valid
  49. $status = $mail, send();
  50. Simple judgment and prompt information
  51. If($status) {
  52. echo ' send mail Success ';
  53. }Else{
  54. Echo ' failed to send message, error message not: '. $mail, errorinfo;
  55. }
  56. ?>

PHP under the use of Phpmailer

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.