目前的另外一个项目“麦客航班”,因為目前服务器托管在江苏,并且居然装的系统是Windows 2003,很让我无奈,因為我们架设的是Wordpress程序,wordpress在缺省无sendmail等UNIX下的邮件服务器时,是无法发送邮件的,诸如用户注册的时候,诸如使用Mail To Commenter插件的时候都需要发送邮件。这时候搜索就是您最好的老师了。果不然,google了一下,我已经有解决方案了。Follow me!
1.在/wp-includes/目录下新建立mail.inc.php文件。文档内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?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 = "你的郵件地址"; var $FromName = "想叫啥就叫啥"; var $Host = "smtp服务器地址"; var $Port = 25; //smtp server port var $SMTPAuth = true; var $Username = "你邮件的帐号"; var $Password = "你邮件的密码"; //var $SMTPDebug = true; var $WordWrap = 75; } ?> |
2.打開/wp-includes/pluggable.php,查找到function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() )
,在global $phpmailer;
之前添加如下代碼
1 2 3 4 5 6 7 8 9 |
require("mail.inc.php"); $mail = new MyMailer; $mail->AddAddress($to); $mail->Subject = $subject; $mail->Body = $message; return $mail->Send(); |
3.繼續在此文檔中查找到wp_new_user_notification函數,修改其中的一行代碼:
把
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
修改成
@wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
4.在文檔結尾?>前添加如下代碼
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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($to); $mail->Subject = $subject; $mail->Body = $message; $mail->AddStringAttachment($string, $filename, $encoding, $type); return $mail->Send(); } endif; |
OK,大功告成。現在可以使用非SSL SMTP Server(比如126)發送郵件了。
以上方法在Wordpress 2.7中測試通過。
评论前必须登录!
注册