473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Getting multiple emails from a single mail()...

I found an old thread on this (http://groups.google.com/group/alt.php/
browse_thread/thread/751edb9c723316c4/ea9bf92a9c6b807c?lnk=gst&q=mail()
+duplicate&rnum=7#ea9bf92a9c6b807c), but there didnt seem to be a
resolution. I also noticed that this was a pretty old thread and there
didn't seem to be anything newer in the search results.

Regardless, I have a very similar problem; I am consistently getting
five emails per each PHP mail() call. While this originally showed up
in a loop generating a flood of email, I explicitly made a single
direct mail call using hard coded strings and I confirmed the same
behavior. I have spent most of today fighting with this and I can
confidently rule out that the mail() function is being accidentally
called multiple times (unless PHP is reloading the page multiple times
before finally rendering back or something else really bizarre)

Here is an example:

$result = mail($sendto, $subject, $messagebody, $headers);

If it matters, this is being called via a wrapper function, like this:

function send_email($email_from, $email_to, $subject, $msg,
$show_result = null)
{
...
$headers = "From: $from \r\n";
$headers .= "Reply-To: $from \r\n";
...
$result = mail($sendto, $subject, $messagebody, $headers);
...
}

The values of the vars don't matter, as I ran a very simple mail with
hard coded strings and got exactly the same behavior.

I have searched extensively and I cant seem to find anything that
specifically nails down why this might happen. For those interested in
the mail headers generated by a single mail() call, here is what I get
(some data scrubbed out):

########################
Received: from crazycooter [67.110.67.194] by XXXXX.marketnet.com
(SMTPD-9.10) id A208038C; Wed, 01 Aug 2007 12:25:28 -0500
Date: Wed, 01 Aug 2007 12:25:17 -0500
Subject: Subject
To: YY*********@MarketNet.com
From: AA*********@MarketNet.com
Reply-To: AA*********@MarketNet.com
Message-Id: <200708011225863.SM03756@crazycooter>
X-RCPT-TO: <YY*********@MarketNet.com>
Status:
X-UIDL: 471469545
X-IMail-ThreadID: c208071f0000b881
########################
Received: from crazycooter [67.110.67.194] by XXXXX.marketnet.com
(SMTPD-9.10) id A2020370; Wed, 01 Aug 2007 12:25:22 -0500
Date: Wed, 01 Aug 2007 12:25:11 -0500
Subject: Subject
To: YY*********@MarketNet.com
From: AA*********@MarketNet.com
Reply-To: AA*********@MarketNet.com
Message-Id: <200708011225800.SM02212@crazycooter>
X-RCPT-TO: <YY*********@MarketNet.com>
Status:
X-UIDL: 471469541
X-IMail-ThreadID: c20100e10000b872
########################
Received: from crazycooter [67.110.67.194] by XXXXX.marketnet.com
(SMTPD-9.10) id A20304C4; Wed, 01 Aug 2007 12:25:23 -0500
Date: Wed, 01 Aug 2007 12:25:13 -0500
Subject: Subject
To: YY*********@MarketNet.com
From: AA*********@MarketNet.com
Reply-To: AA*********@MarketNet.com
Message-Id: <200708011225488.SM03132@crazycooter>
X-RCPT-TO: <YY*********@MarketNet.com>
Status:
X-UIDL: 471469542
X-IMail-ThreadID: c20301a00000b875
########################
Received: from crazycooter [67.110.67.194] by XXXXX.marketnet.com
(SMTPD-9.10) id A20503A8; Wed, 01 Aug 2007 12:25:25 -0500
Date: Wed, 01 Aug 2007 12:25:15 -0500
Subject: Subject
To: YY*********@MarketNet.com
From: AA*********@MarketNet.com
Reply-To: AA*********@MarketNet.com
Message-Id: <200708011225363.SM03132@crazycooter>
X-RCPT-TO: <YY*********@MarketNet.com>
Status:
X-UIDL: 471469543
X-IMail-ThreadID: c20507190000b87a
########################
Received: from crazycooter [67.110.67.194] by XXXXX.marketnet.com
(SMTPD-9.10) id A20703A8; Wed, 01 Aug 2007 12:25:27 -0500
Date: Wed, 01 Aug 2007 12:25:16 -0500
Subject: Subject
To: YY*********@MarketNet.com
From: AA*********@MarketNet.com
Reply-To: AA*********@MarketNet.com
Message-Id: <200708011225706.SM03132@crazycooter>
X-RCPT-TO: <YY*********@MarketNet.com>
Status:
X-UIDL: 471469544
X-IMail-ThreadID: c20600e10000b87d
########################

I am developing locally right now on a WinXP box (SP2) with PHP 5 via
IIS. If it matters, I had to configure IIS such that .html extensions
are mapped to "C:\Progra~1\PHP\php5isapi.dll" for GET,POST, and HEAD
since this clients site is all .html files with embedded PHP. The SMTP
is an exchange server.

I didn't develop this app, but I do need to support it, so any
guidance from someone more knowledgeable would be greatly appreciated.

Regards,

CrazyCooter

Aug 1 '07 #1
10 2990
cr*********@gmail.com wrote:
[...] The SMTP is an exchange server.
Can you telnet to the SMTP server and send a raw email by hand? It mat help
you to know if the error is whithin that exchange server.

(Have a look at Wikipedia for hints on the SMTP commands. They go something
like "HELO", "RCPT TO", and the message body followed by a line with a
single dot, IIRC.)
Hope it helps,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
Aug 1 '07 #2
I followed through the steps (pretty cool hehe) and I got a single
email as a result.

CrazyCooter

Aug 1 '07 #3
cr*********@gmail.com wrote:
I followed through the steps (pretty cool hehe) and I got a single
email as a result.

CrazyCooter
It really looks like you're calling mail() five times. Try sometning
like this:

function send_email($email_from, $email_to, $subject, $msg,
$show_result = null)
{
static count = 1;
...
$headers = "From: $from \r\n";
$headers .= "Reply-To: $from \r\n";
...
$messagebody = "Count: " . $count++ . "\n\n" . $messagebody;
$result = mail($sendto, $subject, $messagebody, $headers);
...
}

This will give an incrementing count at the start of the message body,
starting at 1.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 2 '07 #4
Rik
On Thu, 02 Aug 2007 05:18:54 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
cr*********@gmail.com wrote:
>I followed through the steps (pretty cool hehe) and I got a single
email as a result.
CrazyCooter

It really looks like you're calling mail() five times. Try sometning
like this:

function send_email($email_from, $email_to, $subject, $msg,
$show_result = null)
{
static count = 1;
$count
...
$headers = "From: $from \r\n";
$headers .= "Reply-To: $from \r\n";
...
$messagebody = "Count: " . $count++ . "\n\n" . $messagebody;
$result = mail($sendto, $subject, $messagebody, $headers);
...
}

This will give an incrementing count at the start of the message body,
starting at 1.
Indeed. Possibly use debug_backtrace() to check where it happens, but most
likely it's an undesired loop and linenumbers will be the same.
--
Rik Wasmus
Aug 2 '07 #5
Rik wrote:
On Thu, 02 Aug 2007 05:18:54 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>cr*********@gmail.com wrote:
>>I followed through the steps (pretty cool hehe) and I got a single
email as a result.
CrazyCooter

It really looks like you're calling mail() five times. Try sometning
like this:

function send_email($email_from, $email_to, $subject, $msg,
$show_result = null)
{
static count = 1;
$count
> ...
$headers = "From: $from \r\n";
$headers .= "Reply-To: $from \r\n";
...
$messagebody = "Count: " . $count++ . "\n\n" . $messagebody;
$result = mail($sendto, $subject, $messagebody, $headers);
...
}

This will give an incrementing count at the start of the message body,
starting at 1.

Indeed. Possibly use debug_backtrace() to check where it happens, but
most likely it's an undesired loop and linenumbers will be the same.
--Rik Wasmus
Thanks, Rik. I should know not to try to post code at midnight... :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 2 '07 #6
C.
On 1 Aug, 22:49, crazycoo...@gmail.com wrote:
>
Regardless, I have a very similar problem; I am consistently getting
five emails per each PHP mail() call. While this originally showed up
in a loop generating a flood of email, I explicitly made a single
direct mail call using hard coded strings and I confirmed the same
behavior. I have spent most of today fighting with this and I can
confidently rule out that the mail() function is being accidentally
called multiple times (unless PHP is reloading the page multiple times
before finally rendering back or something else really bizarre)
<snip>
>
I am developing locally right now on a WinXP box (SP2) with PHP 5 via
IIS. If it matters, I had to configure IIS such that .html extensions
are mapped to "C:\Progra~1\PHP\php5isapi.dll" for GET,POST, and HEAD
since this clients site is all .html files with embedded PHP. The SMTP
is an exchange server.
You should really think about upgrading to a proper web host and MTA.

There are 3 obvious possiblities:
1) one invocation of mail() is sending lots of messages
2) the page is being invoked multiple times for a single request
3) the MTA is translating one request from the webserver into multiple
emails

Check your webserver log to see how many times the page is being
rendered (2)
Use Wireshark to see how many times the page is being requested by
your browser(2) and what requests it is sending to the MTA (3).

If you're still stuck ask for more help explaining what you have now
discovered.

HTH

C.

Aug 2 '07 #7
Unfortunately I don't have any control over this clients hosting
environment and development path, I just need to fix this up and move
on down the road.

As stated, I am 100% sure my logic looping isn't the problem. I
explicitly added a single line, out side of any loop, with static
arguments and received the same behavior (per original post).

Thanks Colin, I will try that.

I will have to confirm there isn't multiple requests (2) for some odd
reason. I did manually submit an email to the server (previous post)
and I only got one as a result, however I will try out WireShark and
see what is actually being submitted (3).

Thanks!

Crazy Cooter

Aug 2 '07 #8
This app has the developmestruction scheme (http://
worsethanfailure.com/Articles/The_Developmestuction_Environment.aspx)
so it took a while to find the right thing to comment out such that I
was able to isolate the problem. The feed back above pointed me in the
right direction and I found something I probably wouldn't have
otherwise.

I don't fully understand all the mechanics here and since the security
model of the site will change I don't have time to dig and fix. It
looks like broken authentication code, but maybe it really works.
<shrugs/>

Here it is...

$auth_usr = $_SERVER['PHP_AUTH_USER'];
$auth_pswd = $_SERVER['PHP_AUTH_PW'];
if(!$auth_usr)
{ header('WWW-Authenticate: Basic realm="Auth"');
}
elseif(in_array(strtolower($auth_usr), $usr))
{ $access = 2;
}

If I comment this code out, I only get one email. If I leave this code
in, I get five emails. I can only assume its bouncing back and forth
to the client for the auth, each time causing the page to reload and
running the mail code again.

Debugging output didn't help (unless it would have been to a log file)
since its only going to show output for the last request which
actually rendered.

Thanks all!

CrazyCooter

Aug 2 '07 #9
Rik
On Thu, 02 Aug 2007 17:07:24 +0200, <cr*********@gmail.comwrote:
This app has the developmestruction scheme (http://
worsethanfailure.com/Articles/The_Developmestuction_Environment.aspx)
so it took a while to find the right thing to comment out such that I
was able to isolate the problem. The feed back above pointed me in the
right direction and I found something I probably wouldn't have
otherwise.

I don't fully understand all the mechanics here and since the security
model of the site will change I don't have time to dig and fix. It
looks like broken authentication code, but maybe it really works.
<shrugs/>

Here it is...

$auth_usr = $_SERVER['PHP_AUTH_USER'];
$auth_pswd = $_SERVER['PHP_AUTH_PW'];
if(!$auth_usr)
{ header('WWW-Authenticate: Basic realm="Auth"');
echo 'unauthorised';
exit;
}
elseif(in_array(strtolower($auth_usr), $usr))
{ $access = 2;
}

If I comment this code out, I only get one email. If I leave this code
in, I get five emails. I can only assume its bouncing back and forth
to the client for the auth, each time causing the page to reload and
running the mail code again.
Yup, exit after an auth header, possibly supplying a 'not authorised' page
just before. If you don't, the code could be run anyway.

--
Rik Wasmus
Aug 2 '07 #10
cr*********@gmail.com wrote:
This app has the developmestruction scheme (http://
worsethanfailure.com/Articles/The_Developmestuction_Environment.aspx)
so it took a while to find the right thing to comment out such that I
was able to isolate the problem. The feed back above pointed me in the
right direction and I found something I probably wouldn't have
otherwise.

I don't fully understand all the mechanics here and since the security
model of the site will change I don't have time to dig and fix. It
looks like broken authentication code, but maybe it really works.
<shrugs/>

Here it is...

$auth_usr = $_SERVER['PHP_AUTH_USER'];
$auth_pswd = $_SERVER['PHP_AUTH_PW'];
if(!$auth_usr)
{ header('WWW-Authenticate: Basic realm="Auth"');
}
elseif(in_array(strtolower($auth_usr), $usr))
{ $access = 2;
}

If I comment this code out, I only get one email. If I leave this code
in, I get five emails. I can only assume its bouncing back and forth
to the client for the auth, each time causing the page to reload and
running the mail code again.

Debugging output didn't help (unless it would have been to a log file)
since its only going to show output for the last request which
actually rendered.

Thanks all!

CrazyCooter
Or, if you set up your webserver configuration properly, the user won't
even be able to get to this page unless he's authorized. The webserver
will stop them.

Then you don't even need this code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 2 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Wm | last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in plain text, not HTML as expected), from a single mail() line... Can anyone tell me what might be causing the duplicates??...
8
by: Good Man | last post by:
Hi I'm building a 'job posting' site of sorts. When a job is available in a particular state, I want the system to send an email to everyone who is 'watching' that state. I know how to do...
2
by: .Net Newbie | last post by:
Hello, I am currently coding my ASP.Net pages in c# and have run into a question concerning Emails. I have four objects on a page (six including 2 buttons). The first is a subject line...
5
by: Kun | last post by:
i have the following code: ---------------------------------- import smtplib from email.MIMEText import MIMEText fp = open('confirmation.txt', 'rb') msg = MIMEText(fp.read()) From =...
15
by: Rainman | last post by:
In the following simplified tag: <a href='mailto:<address1@somewhere.com>,<address2@nowhere.com>?subject=Testing'> click here</a> When clicked, both addresses appear as "To:" recipients when...
5
by: Jai | last post by:
Hi, I am in a problem of sending mass emails(newsletter) to my website members. Actually my problem is this: I want to send newsletter to my website members. But I had given a facility for...
10
by: ll | last post by:
Hi, I currently am using the following regex in js for email validation, in which the email addresses can be separated by commas or semicolons. The problem, however, lies in that I can type two...
0
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
Like many people, I normally use Yahoo! Mail via the web and like to keep all my emails stored on the Yahoo! server. However sometimes I can’t get access to a PC/the web and I download my emails...
2
by: palanisiva | last post by:
Hi, I am using PHP mailer to send out 2 different emails. The problem I am having is only the first email is ever sent out. Below is my code. The first email $to but i add two mail id mail not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.