【www.bbyears.com--WordPress】
查看我的效果图
上面的链接介绍内容大致为 发邮件到blogmail@188.com,邮件标题为文章标题,邮件内容为文章内容 这个就简单了 直接上代码,下面是我封装好的方法,添加到主题下面的function.php文件这里多说一句:原因是之前群里一新手不知道function.php文件在哪里,路径为 “根目录\wp-content\themes\主题目录/function.php”
代码如下function auto_send_to_163($mail_info,$get_data){
if(get_post_meta($get_data["post_id"],"_auto_send_to_163")){
echo get_permalink($get_post_id)."已经同步".$website."
\n";
return false;
}
require_once ABSPATH . WPINC . "/class-phpmailer.php";
require_once ABSPATH . WPINC . "/class-smtp.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host =$mail_info["host"];
$mail->CharSet="utf-8";
$mail->SMTPAuth =TRUE; // 启用SMTP验证功能
$mail->Username = $mail_info["username"];
$mail->Password = $mail_info["password"];; // 邮局密码
$mail->From =$mail_info["username"];
$mail->FromName="小松博客";
$mail->AddAddress("blogmail@188.com", "");
$mail->Subject = $get_data["post_title"]; //邮件标题
$mail->Body = $get_data["post_content"]; //邮件内容
$mail->Send();
add_post_meta($get_data["post_id"],"_auto_send_to_163","1",true);
}
如果你要实时通文章到网易博客添加下面的代码
代码如下function auto_send_to_163($post_ID){
$get_post_info = get_post($post_ID);
$get_post["post_content"] = $get_post_info->post_content;
$get_post["post_title"] = $get_post_info->post_title;
$get_post["post_id"] =$post_ID
$xmlclient["username"]="";//网易博客用户名
$xmlclient["password"]="";//网易博客密码
$xmlclient["host"]="smtp.163.com";
auto_send_to_163($xmlclient,$get_post);
}
add_action("publish_post", "send_to_boke", 0);