现在的位置: 首页网站调试>正文
wordpress使用godaddy主机不能自动发送邮件的解决方案
发表于476 天前 网站调试 评论数 5

wordpress使用godaddy主机不能自动发送邮件的解决方案

打开你Wordpress主题的functions.php文件,在<?php和?>之间添加以下代码:

</pre>
//comment_mail_notify(所有的回复都会发邮件通知)
function comment_mail_notify($comment_id)  {
$comment = get_comment($comment_id);
$parent_id =  $comment->comment_parent ? $comment->comment_parent :  '';
$spam_confirmed = $comment->comment_approved;
if (($parent_id !=  '') && ($spam_confirmed != 'spam')) {
$wp_email = 'no-reply@' .  preg_replace('#^www\.#', '',  strtolower($_SERVER['SERVER_NAME']));
//此处是发件人的邮箱地址,默认是自动以你的域名为后缀,比如我的是"@yuelongr.cn",也可自行修改为其他的.
$to  = trim(get_comment($parent_id)->comment_author_email);
$subject =  '您在['.get_option("blogname").']的留言有了回复';
//此处是邮件的标题,如果是godaddy主机,标题太长邮件可能发送失败,比如"您在[乐龙博客]的留言有了回复"可正常发送
//以下为邮件内容,也可自行修改为其他的.
$message  = '
<div style="background-color:#eef2fa; border:1px solid #d8e3e8;  color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px;  -khtml-border-radius:5px;">
<p>'.trim(get_comment($parent_id)->comment_author).',  您好!</p>
<p>这是您在《'.get_the_title($comment->comment_post_ID).'》中的留言:<br  />'
.trim(get_comment($parent_id)->comment_content).'</p>
<p>以下是  '.trim($comment->comment_author).' 给您的回复:<br  />'
.trim($comment->comment_content).'<br  /></p>
<p>您可以<a href="' .  htmlspecialchars(get_comment_link($parent_id)) .  '">点击这里查看回复的完整内容.</a></p>
<p>欢迎再度光临 <a href="' .  get_option('home') . '">' . get_option('blogname') .  '</a></p>
<p>(注:此邮件由系统自动发出,请勿回复!)</p>
</div>';
$from  = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers =  "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') .  "\n";
wp_mail( $to, $subject, $message, $headers );
}
}//Modify by  Yuelongr.cn
add_action('comment_post', 'comment_mail_notify');

主要原理应该是用wp_mail函数代替了mail()函数,因为Godaddy的WIN主机禁用了mail()函数.

如果是Godaddy的WIN主机那么还需要继续接着加入以下代码才能真正实现该功能,其他主机就不用了.

&lt;/pre&gt;
&lt;blockquote&gt;//配置开启<a href="http://www.errorgo.com/godaddy-host-wordpress-ato-blogrol-login-for.html"target="_blank"title="Godaddy空间" >GODADDY空间</a>的SMTP发送邮件功能,如果不是GODADDY的WIN空间,则不需要这段.
function  Mailer(&amp;$mailer){
$mailer-&gt;CharSet =  &quot;UTF-8&quot;;
$mailer-&gt;IsSMTP();
$mailer-&gt;SMTPAuth   =  false;
$mailer-&gt;SMTPSecure = &quot;&quot;;//&quot;ssl&quot;
$mailer-&gt;Host       =  &quot;relay-hosting.secureserver.net&quot;;
$mailer-&gt;Port       =  25;
$mailer-&gt;Username   = &quot;&quot;;
$mailer-&gt;Password   = &quot;&quot;;
}//Modify  by Yuelongr.cn
add_action('phpmailer_init','Mailer');

Godaddy的WIN主机是支持SMTP功能的,但是,他只支持他自己的主机,即″relay-hosting.secureserver.net”,本站www.ErrorGo.com测试成功!

wordpress使用godaddy主机不能自动发送邮件的解决方案:目前有5 条留言

  1. admin : 2011年02月01日上午 8:34 回复

    试一下

  2. NianQing : 2011年04月16日下午 10:52 回复

    QQ邮箱是不行的

    • admin : 2011年04月16日下午 11:23 回复

      我测试可以的,要不我发给你测试一下

      • NianQing : 2011年04月17日上午 12:35 回复

        俺用的Godaddy的Linux主机,但是收不到邮件哈! 一样的代码在其他主机里面可以!

        • NianQing : 2011年04月24日下午 1:03 回复

          上面的方法不适合于Godaddy主机,解决办法:http://www.nianqing.info/godaddy-wordpress.html

给我留言


/ 快捷键:Ctrl+Enter
不想听你唠叨×