Recently, a friend made a blog using WordPress, but he was worried about sending emails. by default, WP cannot send emails to Unix mail servers, such as Sendmail. I have been busy for two days and basically solved this problem. while hanging out in the community, a dude mentioned that phpmailer could be used. Later, he checked all wp2.2 files and found that it had come with this stuff. however, you have to make a small modification to get it to work. Thanks to this brother, all the code comes from its website ^_^ (I don't know the PHP language 555 ...), start to pull
1. open the class-phpmailer.php under the/WP-uplodes/directory to find the class. SMTP. PHP replaces it with a class-smtp.php (the official phpmailer file names are class. phpmailer. PHP and class. SMTP. PHP, put in WP later, may be to unify the file naming method is changed to the class-phpmailer.php and class-smtp.php, but forget to change the file name called inside together, hehe)
2. Create mail. Inc. php In the/WP-directdes/directory (set SMTP to be used for sending emails). The Code is as follows:
<? PHP
Require ("class. phpmailer. php ");
Class mymailer extends phpmailer {
// Set default variables for all new objects
VaR $ Mailer = "SMTP"; // alternative to issmtp ()
VaR $ charset = "UTF-8 ";
VaR $ from = "your email address ";
VaR $ fromname = "name, you can think of any name ";
VaR $ host = "SMTP server address ";
VaR $ Port = 25; // SMTP server port
VaR $ smtpauth = true;
VaR $ username = "your email account ";
VaR $ Password = "your email password ";
// Var $ smtpdebug = true;
VaR $ wordwrap = 75;
}
?>
3. Open/WP-nodes des/pluggable. php and find function wp_mail ($ to, $ subject, $ message, $ headers = ''){
Global $ phpmailer; Add the following code before global $ phpmailer.
Require ("mail. Inc. php ");
$ Mail = new mymailer;
$ Mail-> addaddress ($ );
$ Mail-> subject = $ subject;
$ Mail-> body = $ message;
Return $ mail-> send ();
4. Search for the wp_new_user_notification function in this file and modify a line of code:
Set
Wp_mail ($ user_email, sprintf (_ ('[% s] your username and password'), get_settings ('blogname'), $ message );
Modify
@ Wp_mail ($ user_email, sprintf (_ ('[% s] your username and password'), get_settings ('blogname'), $ message );
5. At the end of the file?> Add the following code
If (! Function_exists ('wp _ mail_attachment ')):
Function wp_mail_attachment ($ to, $ subject, $ message, $ string, $ filename, $ encoding, $ type ){
Require ("mail. Inc. php ");
$ Mail = new mymailer;
$ Mail-> addaddress ($ );
$ Mail-> subject = $ subject;
$ Mail-> body = $ message;
$ Mail-> addstringattachment ($ string, $ filename, $ encoding, $ type );
Return $ mail-> send ();
}
Endif;
OK. Now, you only need to set the SMTP server address, port, user name, and password in mail. Inc. php to use a non-SSL SMTP server (such as 163) to send the email.
PS: PhP seems to use the configuration version better. After the above Code is added, You have to enable user registration in the background first. Otherwise, you cannot send emails.