Function Code for sending mails in phpmail

Source: Internet
Author: User

With the phpmail class, you don't have to worry about it. This is a class written by a foreigner. We just need to "take it. The following is a function written based on the send () method in this class: CopyCode The Code is as follows: function send_mail ($ title, $ content, $ from, $ to, $ charset = 'gbk', $ attachment = '')
{
Include '/class/phpmail. Class. php ';
Header ('content-type: text/html; charset = '. $ charset );
$ Mail = new phpmailer ();
$ Mail-> charset = $ charset; // sets the gb2312 Chinese encoding.
$ Mail-> issmtp (); // you can use SMTP to send emails.
$ Mail-> host = "smtp.qq.com"; // set the email server address
$ Mail-> Port = 25; // set the mail server port. The default value is 25.
$ Mail-> from = $ from; // you can specify the sender's email address.
$ Mail-> fromname = ""; // you can specify the sender's name.
$ Mail-> smtpauth = true; // set whether password verification is required for SMTP. True indicates that password verification is required.
$ Mail-> username = $ from; // you can specify the email address for sending an email.
$ Mail-> Password = ""; // set the mailbox Password
$ Mail-> subject = $ title; // you can specify the mail title.
$ Mail-> altbody = "text/html"; // optional, comment out and test
$ Mail-> body = $ content; // you can specify the email content.
$ Mail-> ishtml (true); // sets whether the content is of the HTML type.
$ Mail-> wordwrap = 50; // you can specify the number of characters in each line.
$ Mail-> addreplyto ("Address", "name"); // you can specify the address of the recipient.
$ Mail-> addaddress ($ to, "star mode training"); // you can specify the recipient address.
If ($ attachment! = '') // Set the attachment
{
$ Mail-> addattachment ($ attachment, $ attachment );
}
If (! $ Mail-> send ())
{
Return false;
} Else {
Return true;
}
}

Generally, QQ mail is used, because it is easy to enable SMTP and POP3 services, and it is free of charge. Pay attention to the content format and encoding of the mail.
Phpmail. Class. php: Click to download it!

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.