mercredi 4 mars 2015

New post in mail to subscriber display in Format


i am going to make functionality like when admin publish any post. post title any few characters of content i send in the mail to our subscribers. every thing is working fine , but their is small problem i am facing. when admin publish post with image it is not displaying in good format in the mail.


what i try :



function email_members($post_ID) {
global $wpdb;
$usersarray = $wpdb->get_results("SELECT eemail_email_sub FROM wp_eemail_newsletter_sub ",OBJECT);
$users = array();
foreach ($usersarray as $prod) {
array_push($users,$prod->eemail_email_sub );
}
$users = implode(",", $users);

$post = $wpdb->get_results(" SELECT * from wp_posts where post_status = 'publish' order by ID desc limit 1");
foreach ($post as $p) {
$content = "<h3>". $p->post_title . "</h3><br/><br/>";
$content .= substr($p->post_content, 0, 800);
$content.="...";
$content .= "<br/><br/>";
$guid = $p->guid;
$content .="<a href='$guid' target='_blank'>Real Blog </a>";
$subject = $p->post_title . " " ."site-Blog";

}
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: noreply@site.com ' . "\r\n";
mail($users,$subject,$content,$headers);
return $post_ID;
}
add_action('publish_post', 'email_members');


it send post title and first 800 characters to subscriber in mail it display like thisInMail.


Please Guide me can we display new post in format in the mail. and tell me if i am doing code in wrong way.


Thanks in advance





Aucun commentaire:

Enregistrer un commentaire