Use smtp.163.com to send mail (local serverless) 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 details, see the following sample code:
The Code is as follows:
/*******************************
* 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 ='
Welcome to http://www.cgsir.com
Thank you for registering as a member of this site!
';
$ Mail-> AltBody = "text/html ";
If (! $ Mail-> Send ())
{
Echo "email sending Error
";
Echo "email error message:". $ mail-> ErrorInfo;
Exit;
}
Else {
Echo "$ user_name email sent successfully!
";
}
}
// 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 you are sending an html-format email, remember to specify it
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.