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!