Forum Moderators: coopster
I am trying to write a script that emails a newsletter to the members in my database.
I have it sending the email however it is not printing the name field in the email when sent.
I even tried setting the name variable like so $name = $r1["name"];
Here is the code I am using:
[PHP]<?
include("../../config.php");
include("../db-connect.php");
if(isset($submit))
{
if(empty($validated))
{
echo "<center><br><br><br> Error.<br> Go <a class=TN href=mail.php> back</a> and make your choice. </center>";
exit;
}
if(empty($message))
{
echo "<center><br><br><br> You are trying to send blank email. <br> Go <a class=TN href=mail.php> back</a> and write some text. </center>";
exit;
}
if($_POST[validated] == 'yes')
{
$q1 = "select email, name from newsletter WHERE validated='yes' ";
$r1 = mysql_query($q1) or die(mysql_error());
$name = $r1["name"];
}
elseif($_POST[validated] == 'no')
{
$q1 = "select email, name from newsletter WHERE validated='no' ";
$r1 = mysql_query($q1) or die(mysql_error());
$name = $r1["name"];
}
while($a1 = mysql_fetch_array($r1))
{
$message = " Dear $name \n\n\n $message";
$from = "From: info@kimberleys.net.au";
mail($a1[0], $subject, $message, $from);
}
echo "<center><br><br><br>The mail was sent successfully. </center>";
unset($validated);
exit;
}
?>[/PHP]
Any help would be GREATLY appreciated.
Good luck!
eelix
$r1 = mysql_query($q1) or die(mysql_error());
$name = $r1["name"];
SHOULD GO SOMETHING LIKE
$r1 = mysql_query($q1) or die(mysql_error());
$r2 = mysql_fetch_array($r1);
$name = $r2["name"];
OR
$r1 = mysql_query($q1) or die(mysql_error());
$r2 = mysql_fetch_array($r1);
$name = $r2['name'];
Habtom
I got it sorted using Dreamcatchers advice, a big thanks to you :)
One more question..
This script is going to be stored in a secure folder, should I add any other security snippets to the code to make it more safe?
Also, will this script handle 100's of emails or is it going to cause problems with timeouts etc?
that depends on how it will be run
as far as timeouts and things go, that all depends on your setup and your ISP. My isp used to block me after about 500 in a row so I had to break it up a bit. As far as script timeouts, I could send about 10K before I had to change the max execution but we were on our own servers so we were tweaked anyway.