Jump to content

looping a record for mail recipients


valoukh

Recommended Posts

Hey!

 

Having trouble looping my mailing list for the "To" field of my mail script:

 

require_once "Mail.php";

$from = "Valoukh <[email protected]>";
$to = while($row = mysql_fetch_array($result)) { echo "" . $_POST[email] . "; "};
$subject = "Newsletter!";
$body = "Hello! <br><br> We'll be at " . $_POST[venue] . " on " . $_POST[gigdate] . ". We hope to see you there! <br><br>Please visit the site for more info!";

 

Any ideas?

 

Thanks, valoukh.

Link to comment
https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/
Share on other sites

best thing to do is not send eveything in the "TO" part. Everyone you send it to will know everyone elses email. send it through the BCC through headers. Also $from should be in your headers not by itself.  Also looks like you are sending html do you will need to add headers for that

 

<?php
while($row = mysql_fetch_array($result)) {
$r[] = $row['email']; // change to whatever the field is for the email address
}

$bcc = implode(", ", $r);
$to = "";
$headers = "From: Valoukh <[email protected]>\r\n";
$headers .= "BCC: $bcc\r\n";
//leave the next 2 lines alone
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$subject = "Newsletter!";
$body = "Hello! <br><br> We'll be at " . $_POST['venue'] . " on " . $_POST['gigdate'] . ". We hope to see you there! <br><br>Please visit the site for more info!";
?>

 

If you have problem remove the \r. Some servers like them some servers don't. Also enclose your post vars in single quotes.

 

Ray

 

i just realised that on top of what you said, I was trying to loop the POST instead of the record, always takes someone else to notice that lol.

 

Just putting together the code as per your reccommendation, will be back with more questions im sure, haha. thanks.

if you get that error then your server is not setup to send mail. The built in mail() function of php will use the server to send mail. If no smtp is set up thenyou will have to use something like phpmailer to do it manually so the server can connect to a mail server and send the mail out.

 

Did the mail work fine before???

 

Ray

Yea! I've already got mail working on one page - it was a simple INSERT to database, followed by an automatic email to the user (try the mailing list form http://www.denbygrace.com/HTML/index.php). The only difference with this one is im trying to send to multiple recipients, pulled from the database mailing list.

 

And I'm not using mail(), but "PEAR Mail package", I followed the instructions here:

 

http://email.about.com/od/emailprogrammingtips/qt/et073006.htm

 

Forgive my lack of understanding, I just expected it to work the same on both pages, regardless of the record loop!

I would suggest using phpmailer. I am not familiar with the PEAR mailer. I use php mailer and it does everything you may need with ease.

 

http://phpmailer.codeworxtech.com/

 

Sorry can't help you with the PEAR mailer but the script I gave you above works with the built in PHP mail function.

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.