Jump to content

Mail function problem.


maestrodamuz

Recommended Posts

I am working on an emailing application and I am using the mail() function.

But any time I send email 2 copies are sent instead. This is my mailing script

 

//create a From: mailheader
$headers = "From:".$_POST['geduemail'];
//loop through results and send mail
while ($row = mysql_fetch_array($emails)) {
set_time_limit(0);
$email = $_POST['email'];
mail("$email", stripslashes($_POST['subject']), stripslashes($_POST['message']), $headers);
}

 

I will appreciate any help in debugging this.

Link to comment
https://forums.phpfreaks.com/topic/140345-mail-function-problem/
Share on other sites

why are you in the loop?

you don't get any vars from $row so i am guessing that the mysql query returns two rows so it sends the email twice

try just

$headers = "From:".$_POST['geduemail'];
set_time_limit(0);
$email = $_POST['email'];
mail("$email", stripslashes($_POST['subject']), stripslashes($_POST['message']), $headers);

or should it look something like this

$headers = "From:".$_POST['geduemail'];
//loop through results and send mail
while ($row = mysql_fetch_array($emails)) {
set_time_limit(0);
$email = $row['email']; //get email from database?
mail("$email", stripslashes($_POST['subject']), stripslashes($_POST['message']), $headers);
}

 

Scott.

 

 

Thanks Scott, I used the $_POST because I am submitting the email value from a form.

I have dealt with the problem, as U rightly asked "why am I in the loop?". The script was actually modified from a mass emailer script, so i have removed the loop and the script is now working fine.

 

Thank you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.