valoukh Posted June 4, 2008 Share Posted June 4, 2008 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 More sharing options...
phpzone Posted June 4, 2008 Share Posted June 4, 2008 Try reading up on loops and database access at the online manual www.hudzilla.org Link to comment https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557301 Share on other sites More sharing options...
valoukh Posted June 4, 2008 Author Share Posted June 4, 2008 I'll have a look, thank you. Just FYI I've used loops many times so I know I can do them, I'm just having a bit of trouble getting this small loop to run within the mail script! Link to comment https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557348 Share on other sites More sharing options...
valoukh Posted June 4, 2008 Author Share Posted June 4, 2008 Hmm, that document doesn't seem to tell me anything I don't already know (when it comes to databases/loops). It's the syntax I'm having trouble with! Anyone? Link to comment https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557380 Share on other sites More sharing options...
craygo Posted June 4, 2008 Share Posted June 4, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557390 Share on other sites More sharing options...
valoukh Posted June 4, 2008 Author Share Posted June 4, 2008 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 https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557423 Share on other sites More sharing options...
valoukh Posted June 4, 2008 Author Share Posted June 4, 2008 im currently getting this error: Failed to set sender: @localhost [sMTP: Invalid response code received from server (code: 501, response: <@localhost>: no local part)] I removed all instances of "\r" Link to comment https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557462 Share on other sites More sharing options...
craygo Posted June 4, 2008 Share Posted June 4, 2008 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 https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557513 Share on other sites More sharing options...
valoukh Posted June 4, 2008 Author Share Posted June 4, 2008 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 https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557568 Share on other sites More sharing options...
craygo Posted June 4, 2008 Share Posted June 4, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108680-looping-a-record-for-mail-recipients/#findComment-557678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.