Phpmailer mail class using smtp.163.com to send mail Method

Source: Internet
Author: User
Tags word wrap

Step 1: Download phpmailerfile package phpmailer-1.73.tar.gz from Open Source Community : Http://phpmailer.sourceforge.net/
Step 2: Check whether your server system supports socket, for example, phpinfo ();
If you do not have this option, note that socket is an extension of PHP, and a configuration option for./configure -- enable-sockets must be given during compilation.

Step 3: extract the file to your web server directory and call the class. Note: The class is included first. phpmailer. PHP, create an object, set parameters, and call member functions. For more information, see the following example. Code : Copy code The Code is as follows: <? PHP
/*******************************
* Author: Li Yingjiang
* Date: 2006-12-7
*******************************/
Require ("phpmailer/class. phpmailer. php ");

Function smtp_mail ($ sendto_email, $ subject, $ body, $ extra_hdrs, $ user_name ){
$ Mail = new phpmailer ();
$ Mail-> issmtp (); // send via SMTP
$ Mail-> host = "200.162.244.66"; // SMTP servers
$ Mail-> smtpauth = true; // turn on SMTP authentication
$ Mail-> username = "yourmail"; // SMTP username Note: @ domain name is not required for normal mail authentication.
$ Mail-> Password = "mailpassword"; // SMTP Password

$ Mail-> from = "yourmail@cgsir.com"; // sender's mailbox
$ Mail-> fromname = "cgsir.com administrator"; // sender

$ Mail-> charset = "gb2312"; // the character set is specified here!
$ Mail-> encoding = "base64 ";

$ Mail-> addaddress ($ sendto_email, "username"); // recipient's email address and name
$ Mail-> addreplyto ("yourmail@cgsir.com", "cgsir.com ");

// $ Mail-> wordwrap = 50; // set word wrap
// $ Mail-> addattachment ("/var/tmp/file.tar.gz"); // attachment
// $ Mail-> addattachment ("/tmp/image.jpg", "new.jpg ");
$ Mail-> ishtml (true); // send as HTML
// Email Subject
$ Mail-> subject = $ subject;
// Email content
$ Mail-> body ='
<HTML> <Meta http-equiv = "content-language" content = "ZH-CN">
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"> <Body>
Welcome to <a href = "http://www.cgsir.com"> http://www.cgsir.com </a> <br/>
Thank you for registering as a member of this site! <Br/>
</Body>
</Html>
';

$ Mail-> altbody = "text/html ";
If (! $ Mail-> send ())
{
Echo "email sending error <p> ";
Echo "email error message:". $ mail-> errorinfo;
Exit;
}
Else {
Echo "$ user_name email sent successfully! <Br/> ";
}
}

// Parameter description (sent to, subject, content, additional information, user name)
Smtp_mail ('yourmail @ cgsir.com ',' Welcome to cgsir.com! ', 'Null', 'cgsir. com', 'username ');

?>

Note:
1. Set the character set of the email, $ mail-> charset = "gb2312"; // specify the character set here! Here I only specify it as gb2312 because outlook can display the mail subject normally, I tried to set it to UTF-8, but garbled characters are displayed in outlook.

2. If the email is in HTML format, remember to specify it as <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

3. If you want to use it for mass mailing, remember to modify the include file function, such:
Require ("phpmailer/class. phpmailer. php ");
Change
Require_once ("phpmailer/class. phpmailer. php ");
Otherwise, the class will be redefined.

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.