Hello Everyone,

My mailer keeps sending duplicates & I can't find the problem in my code. I would appreciate it if someone could look it over & point out the problem.

<?
if($action == "mail") {

$success=0;
$failed=0;

$headers .= "From: Golden Planet Clubs PTC Admin  <admin@ptc.goldenplanetclub.com>\n";
$headers .= "Reply-To: <admin@ptc.goldenplanetclub.com>\n";
$headers .= "X-Sender: <News@ptc.goldenplanetclub.com>\n";
$headers .= "X-Mailer: PHP4\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <admin@ptc.goldenplanetclub.com>\n";
$subject = stripslashes($subject);
$msg = stripslashes($msg);

echo "Your message is being sent!<br><br><table>";

$sql=$Db1->query("SELECT * FROM user");
while($userinfo=$Db1->fetch_array($sql)) {
	$to=$userinfo['email'];
	if(@mail($to,$subject,$msg,$headers)) {
		$result="<font color=\"darkgreen\">Success!</font>";
		$success++;
	}
	else {
		$result="<font color=\"darkred\">Failed!</font>";
		$failed++;
	}
	
	echo "<tr><td>$to</td><td>$result</td></tr> ";
	flush();
}
echo "</table>";
$Db1->sql_close();
$includes[content] = "
<script>
if(confirm('Failed: $failed  |  Successes: $success')) {
	location.href='index.php?view=admin&ac=stats';
}
</script>";
}

else {
$includes[content]="
<div align=\"center\">
<form action=\"index.php?view=admin&ac=mailer&action=mail&s=$s\" method=\"post\">


<table cellspacing=\"0\" cellpadding=\"0\" border=0 bgcolor=\"#C6DAE2\" width=\"100%\">
	<tr>
		<td>
			<table cellspacing=\"1\" cellpadding=\"5\" border=0 width=\"100%\">
				<tr bgcolor=\"#F1F6F7\">
					<td valign=\"top\" width=\"100%\">Subject:</td>
					<td><input type=\"text\" name=\"subject\" size=\"35\"></td>
				</tr>
				<tr bgcolor=\"#F1F6F7\">
					<td valign=\"top\">Message:</td>
					<td><textarea cols=50 rows=13 name=\"msg\"></textarea></td>
				</tr>
				<tr bgcolor=\"#F1F6F7\">
					<td colspan=3 align=\"center\"><input type=\"submit\" value=\"Mail Them Now\"></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
</div>
";

}
?>

Thanks,
Joseph.

Recommended Answers

All 17 Replies

At line2 -

if(isset($action) && $action == "mail") {
//your code
}

At line2 -

if(isset($action) && $action == "mail") {
//your code
}

I don't quite understand- I should change it to what you show? & what do you mean "your code"?

Thanks

do you mean the rest of the page code?

you sending the mail on submit or send mail button (say), so to check that on form submit you need to dop what I wrote above.Your modified code below-

<?
if(isset($action) && $action == "mail") {

$success=0;
$failed=0;

$headers .= "From: Golden Planet Clubs PTC Admin  <admin@ptc.goldenplanetclub.com>\n";
$headers .= "Reply-To: <admin@ptc.goldenplanetclub.com>\n";
$headers .= "X-Sender: <News@ptc.goldenplanetclub.com>\n";
$headers .= "X-Mailer: PHP4\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <admin@ptc.goldenplanetclub.com>\n";
$subject = stripslashes($subject);
$msg = stripslashes($msg);

echo "Your message is being sent!<br><br><table>";

$sql=$Db1->query("SELECT * FROM user");
while($userinfo=$Db1->fetch_array($sql)) {
	$to=$userinfo['email'];
	if(@mail($to,$subject,$msg,$headers)) {
		$result="<font color=\"darkgreen\">Success!</font>";
		$success++;
	}
	else {
		$result="<font color=\"darkred\">Failed!</font>";
		$failed++;
	}
	
	echo "<tr><td>$to</td><td>$result</td></tr> ";
	flush();
}
echo "</table>";
$Db1->sql_close();
$includes[content] = "
<script>
if(confirm('Failed: $failed  |  Successes: $success')) {
	location.href='index.php?view=admin&ac=stats';
}
</script>";
}

else {
$includes[content]="
<div align=\"center\">
<form action=\"index.php?view=admin&ac=mailer&action=mail&s=$s\" method=\"post\">


<table cellspacing=\"0\" cellpadding=\"0\" border=0 bgcolor=\"#C6DAE2\" width=\"100%\">
	<tr>
		<td>
			<table cellspacing=\"1\" cellpadding=\"5\" border=0 width=\"100%\">
				<tr bgcolor=\"#F1F6F7\">
					<td valign=\"top\" width=\"100%\">Subject:</td>
					<td><input type=\"text\" name=\"subject\" size=\"35\"></td>
				</tr>
				<tr bgcolor=\"#F1F6F7\">
					<td valign=\"top\">Message:</td>
					<td><textarea cols=50 rows=13 name=\"msg\"></textarea></td>
				</tr>
				<tr bgcolor=\"#F1F6F7\">
					<td colspan=3 align=\"center\"><input type=\"submit\" value=\"Mail Them Now\"></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
</div>
";

}
?>

Ok- I'll give it a try,

Thank you.

Well, I tried it & still the same result. Any other suggestions?

Thanks,
Joseph

Post your htm here which send the mail actually

There are no htm files- they are all php

Then depending on which condition , you intend to fire the mail?
From where "$action" is getting set?

Can you explain that a little more? I'm not sure what you mean.
Thank you,
Joseph

Can you explain that a little more? I'm not sure what you mean.
Thank you,
Joseph

PHP is a server side scripting language (by server side we mean, the code is situated at the server and gets executed at the server only and the result is sent to the client machine) , which provides the way to produce the otherwise static html in a dynamic manner.
Now something about your HTML, html has a element form, which contains different elements like table,div,buttons or submit button etc.
Once you click the submit button, your form gets submitted, and your php code on submit of which you want to get executed has to be coded the way i said.
So if(isset($_post) && $_post !='')
{
//Now code to send the mail
}

Well, I tried the first line you mentioned & it still sent duplicates.
There are no html files in this script. So your saying I should now try the new line of code you just put up?

Unless you explain what exactly you trying to do , nobody here will be able to solve your problem.So far you have been just confusing

The script I showed in my original post is for the mailer on my PTC site.
When I send out an email to my members it always sends 2 emails instead of just one...

I used the line of code you gave me & it didn't solve the problem.
Then you ask for htm files- there are NONE. All the files are php.

Now you show me another line of code, so I asked "am I supposed to use that line now instead???

How is that confusing???

I meant your html which shows textarea, buttons etc ;, which can be inside the php file too and not necessarily the html files.

there is only a form in html which is this:

<div align=\"center\">
<form action=\"index.php?view=admin&ac=mailer&action=mail&s=$s\" method=\"post\">


<table cellspacing=\"0\" cellpadding=\"0\" border=0 bgcolor=\"#C6DAE2\" width=\"100%\">
	<tr>
		<td>
			<table cellspacing=\"1\" cellpadding=\"5\" border=0 width=\"100%\">
				<tr bgcolor=\"#F1F6F7\">
					<td valign=\"top\" width=\"100%\">Subject:</td>
					<td><input type=\"text\" name=\"subject\" size=\"35\"></td>
				</tr>
				<tr bgcolor=\"#F1F6F7\">
					<td valign=\"top\">Message:</td>
					<td><textarea cols=50 rows=13 name=\"msg\"></textarea></td>
				</tr>
				<tr bgcolor=\"#F1F6F7\">
					<td colspan=3 align=\"center\"><input type=\"submit\" value=\"Mail Them Now\"></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
</div>

other than that it's all php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.