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 <valoukh@valoukh.com>";
$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
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 <valoukh@valoukh.com>\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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.