PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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.
$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?!
$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.