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 <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. Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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? Quote Link to comment 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 <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 Quote Link to comment 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. Quote Link to comment 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" Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.