Page 1 of 1
mass mailer - can't make 6 lines of code work!
Posted: Thu Dec 18, 2008 1:17 pm
by dems
Hey everyone! I'm a first time poster here and am completely stuck. This is a mass mailer script that was built to pull emails for a time period out of our database and send them a promotional email.
Code: Select all
$emails = mysql_query("SELECT DISTINCT email FROM orders.orders WHERE time > '2008-11-01 11:40:34' AND time < '2008-11-31 11:40:34'");
if($_POST['action'] == "mailit") {
while($email = mysql_fetch_row($emails)) {
if(!mail($email, $_POST['subject'], stripslashes($_POST['message']), $header)) echo "E-Mail Failed.";
}
}
If I manually set an email address in the code, it works! I am pretty sure this is something simple that I am overlooking. Any ideas?
Thank you!
Re: mass mailer - can't make 6 lines of code work!
Posted: Thu Dec 18, 2008 1:25 pm
by syth04
dems wrote:Hey everyone! I'm a first time poster here and am completely stuck. This is a mass mailer script that was built to pull emails for a time period out of our database and send them a promotional email.
Code: Select all
$emails = mysql_query("SELECT DISTINCT email FROM orders.orders WHERE time > '2008-11-01 11:40:34' AND time < '2008-11-31 11:40:34'");
if($_POST['action'] == "mailit") {
while($email = mysql_fetch_row($emails)) {
if(!mail($email, $_POST['subject'], stripslashes($_POST['message']), $header)) echo "E-Mail Failed.";
}
}
If I manually set an email address in the code, it works! I am pretty sure this is something simple that I am overlooking. Any ideas?
Thank you!
Might want to show us your <form>. Also you might want to check your query. For Example;
Code: Select all
$emails = mysql_query("SELECT DISTINCT email FROM orders.orders WHERE time > '2008-11-01 11:40:34' AND time < '2008-11-31 11:40:34'");
echo "<br /><b>" . $email . " </b>";
if($_POST['action'] == "mailit") {
while($email = mysql_fetch_row($emails)) {
if(!mail($email, $_POST['subject'], stripslashes($_POST['message']), $header)) echo "E-Mail Failed.";
}
}
Re: mass mailer - can't make 6 lines of code work!
Posted: Thu Dec 18, 2008 1:39 pm
by dems
syth04 wrote:Might want to show us your <form>. Also you might want to check your query. For Example;
Here is the whole page...
Code: Select all
$emails = mysql_query("SELECT DISTINCT email FROM orders.orders WHERE time > '2008-11-01 11:40:34' AND time < '2008-11-31 11:40:34'");
$header = 'From: "ME" <sales@site.com>'."\n";
$header .= 'Reply-to: "ME" <sales@site.com>'."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: text/html\n";
if($_POST['action'] == "mailit") {
while($email = mysql_fetch_row($emails)) {
if(!mail($email, $_POST['subject'], stripslashes($_POST['message']), $header)) echo "E-Mail Failed.";
}
}
<form method="post" onsubmit='return confirm("Are you sure you want to send this email to ALL users?");' name="mailer">
<input type="hidden" name="action" value="mailit">
<table width="50%" style="border: 1px solid black;" align="center" rules=rows cellspacing="2" cellpadding="8">
<tr>
<td colspan="2" align="center"><font face="verdana" size="14">Mass Mailer</font> </td>
</tr>
<tr>
<td rowspan="2" valign="middle" align="center" width="30%">Mailer Options</td>
<td><input type="text" name="subject" size="70" value="Enter Subject Here"></td>
</tr>
<tr>
<td><textarea name="message" rows="15" cols="55">Enter your message here</textarea></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="E-Mail this message">
</td>
</table>
</form>
I tried what what you suggested above, but its not echo'ing out anything. I think the query is right because when I paste it into mysql, it does give me a list of email addresses. Maybe its not being implemented correctly?!
Thanks again for any help!!
Re: mass mailer - can't make 6 lines of code work!
Posted: Thu Dec 18, 2008 1:52 pm
by syth04
dems wrote:syth04 wrote:Might want to show us your <form>. Also you might want to check your query. For Example;
Here is the whole page...
Code: Select all
$emails = mysql_query("SELECT DISTINCT email FROM orders.orders WHERE time > '2008-11-01 11:40:34' AND time < '2008-11-31 11:40:34'");
$header = 'From: "ME" <sales@site.com>'."\n";
$header .= 'Reply-to: "ME" <sales@site.com>'."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: text/html\n";
if($_POST['action'] == "mailit") {
while($email = mysql_fetch_row($emails)) {
if(!mail($email, $_POST['subject'], stripslashes($_POST['message']), $header)) echo "E-Mail Failed.";
}
}
<form method="post" onsubmit='return confirm("Are you sure you want to send this email to ALL users?");' name="mailer">
<input type="hidden" name="action" value="mailit">
<table width="50%" style="border: 1px solid black;" align="center" rules=rows cellspacing="2" cellpadding="8">
<tr>
<td colspan="2" align="center"><font face="verdana" size="14">Mass Mailer</font> </td>
</tr>
<tr>
<td rowspan="2" valign="middle" align="center" width="30%">Mailer Options</td>
<td><input type="text" name="subject" size="70" value="Enter Subject Here"></td>
</tr>
<tr>
<td><textarea name="message" rows="15" cols="55">Enter your message here</textarea></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="E-Mail this message">
</td>
</table>
</form>
I tried what what you suggested above, but its not echo'ing out anything. I think the query is right because when I paste it into mysql, it does give me a list of email addresses. Maybe its not being implemented correctly?!
Thanks again for any help!!
So the query did not echo out? This might be a form problem. Try adding the page name to the form attributes.
Code: Select all
<form action="some.php" method="post" name="mailer" onsubmit='return confirm("Are you sure you want to send this email to ALL users?");'>
Re: mass mailer - can't make 6 lines of code work!
Posted: Thu Dec 18, 2008 3:28 pm
by dems
syth04 wrote:So the query did not echo out? This might be a form problem. Try adding the page name to the form attributes.
Code: Select all
<form action="some.php" method="post" name="mailer" onsubmit='return confirm("Are you sure you want to send this email to ALL users?");'>
No it will not echo out. I added the page name as you suggested and still no luck!