彻底解决wordpress mu 收不到邮件问题
原帖来自我的博客:[url=http://www.foolpig.com/2008/05/23/wordpress-mu-sendmail/]http://www.foolpig.com/2008/05/23/wordpress-mu-sendmail/[/url]有个朋友说如何才能解决wordpress mu收不到邮件的问题呢?
我记得wordpress mu默认发送邮件是没有问题的,可是有些邮件服务器却无法收到,比如hotmail,估计是由于采用的Linux默认的sendmail,没有经过认证,所以被邮件服务器给丢弃了
那应该如何解决呢?
我以前写过一篇文章[url=http://wordpress.org.cn/thread-12158-1-1.html][url=http://www.foolpig.com/2008/04/14/wordpress-mu-ne/][color=#800080]《让wordpress mu新用户注册后的密码明文显示,取消邮件通知》[/color][/url][/url]
上面有无法接收邮件时,直接在注册完成后显示用户和密码的方法
可是如果一定要使用邮件怎么办?
既然采用Linux内部的有时候收不到,那能不能采用外部的邮件系统呢?
仔细看了源码,发现wordpress使用的是phpmailer来进行邮件的发送
这样的话使用外部的邮件系统来发送应该问题不大,测试后采用如下步骤解决之:^__^
如果你觉得下面的东东比较麻烦,你可以[url=http://www.foolpig.com/wp-content/uploads/wordpress_mu.zip][color=#0000ff]点这里直接下载[/color][/url]修改后的文章, 下载后解压至 /wp-includes/ 目录下, 记得要修改 mail-inc.php 文件中的邮件信息哦.
1)在 /wp-includes/ 新建 mail-inc.php 文件(这个文件主要是设置 SMTP 服务器的信息), 代码如下:[code]
<?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 = "name,你想起什么名字都可以";
var $Host = "smtp服务器地址";
var $Port = 25; //smtp server port
var $SMTPAuth = true;
var $Username = "你邮件的帐号";
var $Password = "你邮件的密码";
var $WordWrap = 75;
}
?>[/code]打开 /wp-includes/pluggable.php, 查找 function wp_mail($to, $subject, $message, $headers = ”) { global $phpmailer;
在 global $phpmail; 其前面添加如下代码:[code]require("mail-inc.php");
$mail = new MyMailer;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $message;
return $mail->Send();[/code]3) 继续在此文件中查找 wp_new_user_notification 函数, 把:[code]wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
// 修改为:
@wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);[/code]好像就是在前面加上一个@而已.
4) 在文结尾(?>)前添加如下代码:[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($to);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddStringAttachment($string, $filename, $encoding, $type);
return $mail->Send();
}
endif;[/code]
如有疑问,欢迎来人来函联系 ^_^
[[i] 本帖最后由 hmilygxl 于 2008-5-28 00:14 编辑 [/i]] 好文章,谢谢分享 标记 ! 你这个wpmu什么版本?我的是1.5.1,怎么没有你说的这个文件? 新版的1.5已经不需要做任何改动,邮件收发正常! [quote]原帖由 [i]pigi[/i] 于 2008-6-6 08:25 发表 [url=http://wordpress.org.cn/redirect.php?goto=findpost&pid=73772&ptid=14020][img]http://wordpress.org.cn/images/common/back.gif[/img][/url]
新版的1.5已经不需要做任何改动,邮件收发正常! [/quote]
呵呵,我的就是1.5版本的,有些就是收不到,比如hotmail,楼上的可以试一试,我文章上有写:)
另外,有些时候你的邮件服务器IP被加入黑名单了(使用ADSL动态IP的一般会被干掉),你再怎么努力都不可能收到的
[[i] 本帖最后由 hmilygxl 于 2008-6-6 08:29 编辑 [/i]] 我也觉得,收不到,多半是服务器问题把,程序本身应该没问题。
呵呵,感谢楼主。目前偶还遇到类似问题。 [quote]原帖由 [i]ruger[/i] 于 2008-5-30 10:17 发表 [url=http://wordpress.org.cn/redirect.php?goto=findpost&pid=71337&ptid=14020][img]http://wordpress.org.cn/images/common/back.gif[/img][/url]
你这个wpmu什么版本?我的是1.5.1,怎么没有你说的这个文件? [/quote]
不知道你说的是哪个文件?
mail-inc.php 这个文件是没有的,是我新建的一个:lol
[[i] 本帖最后由 hmilygxl 于 2008-6-9 10:48 编辑 [/i]] 请问我是hotmail的邮箱,邮件服务器应该怎么设置呢?
页:
[1]