Friday, 15 July 2011

PHP: Send more than article in one email -



PHP: Send more than article in one email -

i have table named 'an_posts' , column within table named 'post_title'. need send email user when select more 'post_title'. code below send 1 'post_title'. why happened , have add together in code email send retrieve 2 or more info database ?

if($_get["action"] == 'sendpostnewsletter') { global $post; $post_id = $_post["post_id"]; $emailtosender = $_post["emailtosender"]; $subjecttitle = $_post["subjecttitle"]; $sql = "select * an_posts post_type = 'post' , post_status = 'publish' , id in ($post_id)"; $formssql = mysql_query($sql); while ( $row = mysql_fetch_array($formssql) ) { $message = ' <div align="center"><h3>'.$row['post_title'].'</h3></div> <br /> <div style="text-align:justify; font-size:16px; font-family:verdana, geneva, sans-serif; font-weight:bold"> '.$row['post_content'].' </div>'; } $message .= "<hr />"; $headers = "from: newsletter <list@domainname.com>" . "\n" ; $headers .= 'mime-version: 1.0' . "\n"; $headers .= 'content-type: text/html; charset=utf-8' . "\n"; wp_mail( $emailtosender , $subjecttitle , $message, $headers ); $result='<div id="message" class="updated fade"><p><strong><h5>done</h5></strong></p></div>'; echo $result; }

you overwriting content of message each loop. instead append it:

//initialize outside loop $message=''; while ( $row = mysql_fetch_array($formssql) ) { //then append - notice dot .= $message .= ' ...

php email

No comments:

Post a Comment