php - Send email to multiple recipients -


i'm building website people (ie mr. smith) fills out questionaire (not shown) , uses mr. smith's "zip code" , find (3) people/reps (ie.. bob, chuck , sally) 'rep members' , have on previous occasion, opted have questionaire's that's mr. smith's zip code emailed them (bob, chuck , sally) respond to.

so below i've pulled mr. smith's zip code "lifezip" , email address "lifeemail" questionaire form previous page , using mr. smith's zip code "lifezip" find (3) people/reps (who happen bob, chuck , sally) stored in separate table "repstable" match mr. smith's zip code can respond mr. smith's questionaire.

i'm having trouble placing multiple emails (ie.. bob, chuck , sally) "to:" field.

whether script sends same email different people separately or they're listed in "to:" field, i'll take either. in advance!

<? session_start(); session_register('lifezip');  // zip code of mr. smith questionaire on previous page session_register('lifeemail'); // email of mr. smith questionaire on previous page   // connect db   $conn = db_connect();   if (!$conn)     return 'could not connect database server - please try later.';   // convert mr. smith's lifezip , lifeemail previous page variable   echo 'use variables below find customer filled out forms previous pages (initial info received page session)';  $customeremailmatch = $_session['lifeemail']; $customerzipmatch = $_session['lifezip'];   //use lifezip/$customerzipmatch above 'match' zip codes in 'repstable' finds (3) emails, in case, (bob, chuck , sally) , grabs emails  $result = mysql_query("select * repstable repzipcode = $customerzipmatch group repid having count(1) <= 3") or die(mysql_error());    // below making sure i'm pulling bob, chuch , sally's email , table id (repid)  while($row = mysql_fetch_array($result)) {  echo '<br />';  echo "rep's email address: ";  echo '<font color="#ff7600">',$row['repemail'], '</font>';  echo '<br />';  echo "rep's id: ";  echo '<font color="#ff7600">',$row['repid'], '</font>';  echo '<hr />';  }  // below i'm having issue.  // want send myself bob, chuck , sally receive mr. smith's "hello" email message. later i'll insert mr. smith's questionaire form information later.  // insert 'repemail' contains multiple emails '$to:' field below , send email  $to = "my static webmaster email"; $to = "???? repemail ????"; // needs have bob, chuck , sally's email here. $subject = "test mail"; $message = "hello! simple email message."; $from = "webmaster @ send me.com"; $headers = "from:" . $from; mail($to,$subject,$message,$headers); echo "mail sent."; 

thanks in advance this, i've been beating myself on week on one. if knows how send out email multiple times different people (1) email listed in 'to' field, that'd great.

easiest way build array of email addresses , loop through them sending individual mail each one:

$recipients = array('youremail@example.com', 'repemail@example.com', 'bob@example.com'); foreach ($recipients $to) {     mail($to,$subject,$message,$headers); } 

(note: not way send bulk email 100s of people, fine in case few addresses.)

if happy have multiple emails in field, need comma separate them:

$to = 'youremail@example.com, repemail@example.com, bobemail@example.com'; mail($to,$subject,$message,$headers); 

edit: can build array of recipients in while loop, like:

$recipients = array(); while($row = mysql_fetch_array($result)) {      $recipients[] = $row['repemail'];     echo '<br />';      echo "rep's email address: ";      echo '<font color="#ff7600">',$row['repemail'], '</font>';      echo '<br />';      echo "rep's id: ";      echo '<font color="#ff7600">',$row['repid'], '</font>';      echo '<hr />'; } 

then add static email address array:

$recipients[] = 'youremail@example.com'; 

and send them before, time doing actual mail part in loop, each recipient:

$subject = "test mail"; $message = "hello! simple email message."; $from = "webmaster @ send me.com"; $headers = "from:" . $from; foreach ($recipients $to) {     mail($to,$subject,$message,$headers); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -