DasHaas Posted May 24, 2007 Share Posted May 24, 2007 I am workong on a script that sends an email to all the email addresses in one of the tables in my database. The email will be created in a form. Once i submit the form I want the script to send an email to each email address in my table. This is what i have thus far and when I submit the form I get the following error ???: sendmail: No recipients specified although -t option used here is my code: <html> <head> <link href="css/StyleSheet1.css" rel="stylesheet" type="text/css"> <body> <!-- standard page header begins --> <table width="100%" class="table1"> <tr> <td><div align="center" class="text2">Send Email to newsletter subscribers </div></td> </tr> </table> <!-- standard page header ends --> <?php // form not yet submitted // display initial form if (!$_POST['submit']) { ?> <br> <table cellpadding="5" cellspacing="5" class="table1"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td valign="top" class="text5">Group</td> <td> </td> </tr> <tr> <td valign="top" class="text5">Subject</td> <td><input name="txtsubject" type="text" class="table2" id="txtsubject" size="50" maxlength="250"></td> </tr> <tr> <td valign="top" class="text5">Email Body</td> <td valign="top" class="text5"><textarea name="txtbody" cols="47" rows="10" class="table2" id="txtbody"></textarea></td> </tr> <tr> <td colspan="2" valign="top" class="text5"><input name="submit" type="submit" id="submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> </tr> </form> </table><br> <br> <?php } else { // includes include('Includes/PXS_Conf.php'); // set up error list array $errorList = array(); $msgsubject = $_POST['txtsubject']; $msgbody = $_POST['txtbody']; // validate text input fields if (trim($_POST['txtsubject']) == '') { $errorList[] = 'Invalid entry: Message Subject'; } if (trim($_POST['txtbody']) == '') { $errorList[] = "Invalid entry: Message Body"; } // check for errors // if none found... if (sizeof($errorList) == 0) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server! Please contact PXS customer support.'); // select database mysql_select_db($db) or die ('Unable to select database! Please contact PXS customer support.'); // generate and execute query $query = "SELECT email FROM PXS_Newsletter WHERE verified = 1"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // send email $To = $row['$result']; $Subject = "<".$msgsubject.">"; $Body = "<".$msgbody.">"; mail($To, $Subject, $Body); // print result echo '<center>Message sent</center>'; // close database connection mysql_close($connection); } else { // errors found // print as list echo '<font size=-1>The following errors were encountered:'; echo '<br>'; echo '<ul>'; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul></font>'; } } ?> <!-- standard page footer begins --> <table width="100%" class="table1"> <tr> <td><div align="center" class="text1"> <div align="center">Copyright © 2006 Projekt-X-Studios. All Rights Reserved </div> </div></td> </tr> </table> </body> </html> Any help would be greatly appreciated :'( Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/ Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 Instead of $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // send email $To = $row['$result']; $Subject = "<".$msgsubject.">"; $Body = "<".$msgbody.">"; mail($To, $Subject, $Body); you should do $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // send email if (mysql_num_rows($result) == 0) { # Error! Could not find email } else { $To = mysql_fetch_result($result, 0, 'email'); $Subject = "<".$msgsubject.">"; $Body = "<".$msgbody.">"; mail($To, $Subject, $Body); } Actually, that will only work for ONE email only. Do you want to send emails to several people? If so it needs to be re-written a little Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-260460 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 I would like to send the email to all the email addresses in my table. Thanks for your help btw Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-260704 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 What needs to change to get it to work? Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-260796 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 btherl seems to be away, can anyone else help me with this? Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-260980 Share on other sites More sharing options...
chigley Posted May 24, 2007 Share Posted May 24, 2007 Assuming the table is called users, and you want to email every user with the address in the email field: <?php $subject = "Test Email Subject"; $body = "Test message body."; $query = mysql_query("SELECT email FROM users") or die(mysql_error()); while($row = mysql_fetch_row($query)) { $email = $row[0]; if(mail($email, $subject, $body)) { echo "Email sent to $email<br />"; } else { echo "<span style=\"color: red;\">Email not sent to $email</span><br />"; } } ?> That can be adapted to suit your needs Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-260995 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 Thanks for your help, I will give this a shot Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261000 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 Im still getting the following error: sendmail: No recipients specified although -t option used Here is my code with the changes you gave me: <html> <head> <link href="css/StyleSheet1.css" rel="stylesheet" type="text/css"> <body> <!-- standard page header begins --> <table width="100%" class="table1"> <tr> <td><div align="center" class="text2">Send Email to newsletter subscribers </div></td> </tr> </table> <!-- standard page header ends --> <?php // form not yet submitted // display initial form if (!$_POST['submit']) { ?> <br> <table cellpadding="5" cellspacing="5" class="table1"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td valign="top" class="text5">Group</td> <td> </td> </tr> <tr> <td valign="top" class="text5">Subject</td> <td><input name="txtsubject" type="text" class="table2" id="txtsubject" size="50" maxlength="250"></td> </tr> <tr> <td valign="top" class="text5">Email Body</td> <td valign="top" class="text5"><textarea name="txtbody" cols="47" rows="10" class="table2" id="txtbody"></textarea></td> </tr> <tr> <td colspan="2" valign="top" class="text5"><input name="submit" type="submit" id="submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> </tr> </form> </table><br> <br> <?php } else { // includes include('Includes/PXS_Conf.php'); // set up error list array $errorList = array(); $msgsubject = $_POST['txtsubject']; $msgbody = $_POST['txtbody']; // validate text input fields if (trim($_POST['txtsubject']) == '') { $errorList[] = 'Invalid entry: Message Subject'; } if (trim($_POST['txtbody']) == '') { $errorList[] = "Invalid entry: Message Body"; } // check for errors // if none found... if (sizeof($errorList) == 0) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server! Please contact PXS customer support.'); // select database mysql_select_db($db) or die ('Unable to select database! Please contact PXS customer support.'); // generate and execute query $query = mysql_query("SELECT email FROM PXS_Newsletter WHERE verified = 1") or die (mysql_error()); $email = $row[0]; // send email $To = $email; $Subject = "<".$msgsubject.">"; $Body = "<".$msgbody.">"; mail($To, $Subject, $Body); // print result echo '<center>Message sent</center>'; // close database connection mysql_close($connection); } else { // errors found // print as list echo '<font size=-1>The following errors were encountered:'; echo '<br>'; echo '<ul>'; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul></font>'; } } ?> <!-- standard page footer begins --> <table width="100%" class="table1"> <tr> <td><div align="center" class="text1"> <div align="center">Copyright © 2006 Projekt-X-Studios. All Rights Reserved </div> </div></td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261010 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 Doh!! i forgot a line, I think its working now. Please excuse the noobness that oozes from my pores lol Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261012 Share on other sites More sharing options...
chigley Posted May 24, 2007 Share Posted May 24, 2007 You missed the while() out...! Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261015 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 lol yeah i'm T3h Noob :-\ Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261016 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 how long do you think it will take to send the email to 100+ users? can i expect some lag time or should it be instant? Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261024 Share on other sites More sharing options...
chigley Posted May 24, 2007 Share Posted May 24, 2007 Not too long I wouldn't have thought. Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261026 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 question, there are three email addresses in the table but only one email address is getting the message. Would the zero in $email = $row[0]; have anything to do with that? Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261175 Share on other sites More sharing options...
DasHaas Posted May 25, 2007 Author Share Posted May 25, 2007 Anyone? ??? Link to comment https://forums.phpfreaks.com/topic/52744-solved-noob-php-mysql-mail-question/#findComment-261627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.