目前的另外一個項目「麥客航班」,因為目前服務器託管在江蘇,並且居然裝的系統是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中測試通過。
代碼由CSDN這位兄弟提供。過完年,我一定得把服務器裝成Linux!
well done 伺服器還是linux或unix的好啊 windows的實在是很麻煩的說
「過完年,我一定得把服務器裝成Linux!」 伺服器是你自己在維護的啊?
@顏小詩:對的,不過win也其實還好,可以在服務器上拖電驢哈哈。
用WIN是挺不爽的!!
這種方法能成功,以前我試過好多都不行!!!
@xiaorsz:過完年就把系統收拾了
發現win下wp老是出問題,今天就被tags問題搞了好久才搞定。
而且發現反應速度明顯變得很低……
方法收鳥後面用的到哈哈~
@plidezus:php還是用linux+apache好阿~哎
@Leeiio:伺服器基本上都是別人幫我搞的,我的半吊子水平還不會搞這些,頂多就是做做界面設計之類的哈哈~
@plidezus:哈,以後多多交流~
你可以使用google的gmail功能呀.就不必在自己的伺服器上有mail server.??
我現在自己的都是在使用這個.覺的很不錯.
@ptubuntu 這裡指的是wordpress系統發送給用戶的郵件~
學習了
2.8 英文,早期版本,,,這個方法不起作用,我用了國內的幾個郵箱都不行,不過後來伺服器被國安抱走了,我也死心了
@Andrew
呃,你的經歷異常強大!
Pingback: 創造 » 讓架設在Windows上的Wordpress也能正常發郵件(Smtp)!
請問LEEIIO,回復用 @username ,並移動上去顯示內容(即貴站的樣子)用什麼修改或插件? 請指教!
@lee 請參見本文 http://philna.com/2008/12/mouseover-to-show-comment-no1/ ,非插件,是前端實現。
太複雜了。。 ❗
@aily:
我想修改自己的風格,加入
@aily:
這個樣式,請問代碼該怎樣加? (ps 小白)
@lee 同樣也很複雜,你想知道么?是否會js?
有小白教程么 🙁
@lee http://www.saywp.com/wordpress/add-reply-function-in-wordpress-thread-comment-with-jquery.html 看你的了。
謝謝 已經找到 reply-to 插件 🙂