Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

PHPmailer send the same e-mail multiple times (sometimes 1, others 4 or 5)

Hello,
I try to develop a system to send e-mail via smtp. I try with gmal account, and I send Email's with PHPmailer class. The system work, but most of the time the system sends the same e-mail several times.
I see in the net in some forum, the problem is caused by a overclocking of gmail.
Please, somebody tell me, how I put PHPmailer sending just one email each time (the same e-mail).

The best regards,
JC
Avatar of Pedro Chagas
Pedro Chagas
Flag of Portugal image

ASKER

Please view the file. Like I said, in this case I receive 5 same e-mails.

mail.jpg
If you use the phpmailer class, is the mode set to "smtp" "mail" or "sendmail" ? I'm guessing php is not the problem, but the mailserver that sends the email. Try alternating the mode.
I use phpmailer! Sometimes works and send just one e-mail, and others they send a lot of the same e-mail. Somebody Tell's me to used the function "sleep" of php, because in this way I don't have a problems about gmail over clocking. I don't try yet, and I not certain if this solution work.

I don't understand one thing, if lot of people use phpmailer, why no body report a error like this one. I am the first?
When you say to alternate the mode, what you mind?
Have other method to send e-mail's from gmail with php? (other solution without PEAR).
Avatar of Marcus Bointon
I agree with Xyptilon2. Are you getting 5 copies of the exact same message, or 5 separate emails that just look the same? If you look at the headers of the multiple messages, are they identical? Are the sane date/time/message ID the same?

Regarding the mode settings of PHPMailer, if you call IsSMTP(), it will use PHPMailer's internal SMTP client instead of PHP's mail() function, which can give you a bit more control and feedback about what exactly is happening to your message.
All the e-mails have different ID, but they are launch at the same time, and just to send one!
I show you the code for you understand, and I show you two heades of that e-mails.
What you thing happening?
* = hide for personal protection
 
//ONE of FIVE E-MAIL========================================
Delivered-To: *********@gmail.com
Received: by 10.103.238.9 with SMTP id p9cs275624mur;
        Sat, 25 Oct 2008 04:18:03 -0700 (PDT)
Received: by 10.214.147.9 with SMTP id u9mr3240498qad.79.1224933481934;
        Sat, 25 Oct 2008 04:18:01 -0700 (PDT)
Return-Path: <*******@gmail.com>
Received: from qw-out-1920.google.com (qw-out-1920.google.com [74.125.92.144])
        by mx.google.com with ESMTP id 5si894978qwg.9.2008.10.25.04.18.00;
        Sat, 25 Oct 2008 04:18:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of *******@gmail.com designates 74.125.92.144 as permitted sender) client-ip=74.125.92.144;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of *******@gmail.com designates 74.125.92.144 as permitted sender) smtp.mail=*******@gmail.com; dkim=pass (test mode) header.i=@gmail.com
Received: by qw-out-1920.google.com with SMTP id 5so504828qwc.14
        for <*******@gmail.com>; Sat, 25 Oct 2008 04:18:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=domainkey-signature:received:received:date:to:reply-to:subject
         :message-id:x-priority:x-mailer:mime-version:content-type:from;
        bh=rFtvxGPZKKbhH8Ka6oqvAvR9gGxTvaW8f/FmTbYVY+s=;
        b=VTkZk4SkUBOqLGDdcpwJ6MuGJpknb7d7UhbPHjIhZTKIqxmW+Rzu/dZc4g8QD0OS9q
         qEpgFlg1Xzw8l0QLEUQWojs4j4Tw2jh2hFP5vFO+iZ5eXdVArAZKbZpAuw5oBkU7GW3r
         iCRL67AI+Fr2HLrT6Lr/aRsz4X9yUcFSobMfg=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=gamma;
        h=date:to:reply-to:subject:message-id:x-priority:x-mailer
         :mime-version:content-type:from;
        b=ORZhQbSIbkiFMJX5t1xUER6Jz8DsBgEhcz2HTtT/pyCW+KE14H1hOhSV2WiY8s1aXg
         T3RXrAS8GSlZAEvoVomnvlR66omzSNsRLOa1IsNLYTja+BINrZaaF6mazSTOqVEu+UyX
         udUaZhqbqf6Oebm07IVJ0kjRW8MT11nt4G7KU=
Received: by 10.214.182.10 with SMTP id e10mr1034250qaf.317.1224933480476;
        Sat, 25 Oct 2008 04:18:00 -0700 (PDT)
Return-Path: <*******@gmail.com>
Received: from smith.byethost17.com ([209.190.85.203])
        by mx.google.com with ESMTPS id 9sm1514176yxs.5.2008.10.25.04.17.58
        (version=SSLv3 cipher=RC4-MD5);
        Sat, 25 Oct 2008 04:17:59 -0700 (PDT)
Date: Sat, 25 Oct 2008 07:17:56 -0400
Return-Path: net@qualquer.com
To: William Smith <*******@gmail.com>
Reply-to: Webmaster <net@qualquer.com>
Subject: =?utf-8?Q?Isto_=C3=A9_o_titulo?=
Message-ID: <345010fbbbaca2e9389f37a58e7113c9@smith.byethost17.com>
X-Priority: 3
X-Mailer: PHPMailer (phpmailer.codeworxtech.com) [version 2.2]
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="b1_345010fbbbaca2e9389f37a58e7113c9"
From: Mailback <*******@gmail.com>
 
//TWO of Five email's==============================================
Delivered-To: *******@gmail.com
Received: by 10.103.238.9 with SMTP id p9cs275621mur;
        Sat, 25 Oct 2008 04:18:02 -0700 (PDT)
Received: by 10.214.26.18 with SMTP id 18mr3238125qaz.83.1224933481134;
        Sat, 25 Oct 2008 04:18:01 -0700 (PDT)
Return-Path: <******@gmail.com>
Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.27])
        by mx.google.com with ESMTP id 7si888625qwb.7.2008.10.25.04.17.59;
        Sat, 25 Oct 2008 04:18:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of *******@gmail.com designates 74.125.92.27 as permitted sender) client-ip=74.125.92.27;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of lixaradadanet@gmail.com designates 74.125.92.27 as permitted sender) smtp.mail=******@gmail.com; dkim=pass (test mode) header.i=@gmail.com
Received: by qw-out-2122.google.com with SMTP id 9so480005qwb.5
        for <gloradin@gmail.com>; Sat, 25 Oct 2008 04:17:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=domainkey-signature:received:received:date:to:reply-to:subject
         :message-id:x-priority:x-mailer:mime-version:content-type:from;
        bh=fGYnJzzwYH0IAYod8e/DjMq4tlcnJAPOnVm4A5Ieg+s=;
        b=cU40J1NahOFDdfTQNKZSj8zR/HJemy2KhgnCXqeuEULtLd9plLseVKYKOugMLdw54f
         P8GyHynhbh0wcWys/KmxPpaEKq9AYqCEvG6ZzL1w2GCYT6cng0caxdfRHmhK/BcR/WRx
         jMdAUVkXudey0veKWBEFHwiJzpyDhpB7Wi43I=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=gamma;
        h=date:to:reply-to:subject:message-id:x-priority:x-mailer
         :mime-version:content-type:from;
        b=L/69fFx0Hih263tw+fxxYo8vmp1XSsZt5XB6rhJMNkHiBijNrmDBzatnc9dGAGrw74
         bAbdgIXALpw6tuaB/rh6Kdsw9Zv1c9ri0KtczAEz6Qsfhx9Pi7MxCLIHNLZuJUjWwYWM
         vo8eVsIdT0eNQGv9cwGWK3OJiVHKQ21iNFRAU=
Received: by 10.215.100.10 with SMTP id c10mr3295346qam.33.1224933479286;
        Sat, 25 Oct 2008 04:17:59 -0700 (PDT)
Return-Path: <******@gmail.com>
Received: from smith.byethost17.com ([209.190.85.103])
        by mx.google.com with ESMTPS id 33sm1508903yxr.3.2008.10.25.04.17.57
        (version=SSLv3 cipher=RC4-MD5);
        Sat, 25 Oct 2008 04:17:58 -0700 (PDT)
Date: Sat, 25 Oct 2008 07:17:56 -0400
Return-Path: net@qualquer.com
To: William Smith <*******@gmail.com>
Reply-to: Webmaster <net@qualquer.com>
Subject: =?utf-8?Q?Isto_=C3=A9_o_titulo?=
Message-ID: <d28feaf1f2a814d8f15659437faba27b@smith.byethost17.com>
X-Priority: 3
X-Mailer: PHPMailer (phpmailer.codeworxtech.com) [version 2.2]
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="b1_d28feaf1f2a814d8f15659437faba27b"
From: Mailback <lixaradadanet@gmail.com>
 
//THE CODE FOR LAUNCH THE ONLY E-MAIL email.php =======================
<?
require_once("class.phpmailer.php");
 
$mail=new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "**********@gmail.com"; // Conta usada de SMTP
$mail->Password = "**********"; // SMTP password
$webmaster_email = "net@qualquer.com"; //Email para resposta
$email="*******@gmail.com"; // Recipiente de email a enviar
$name="William Smith"; // Nome da caixa de correio
$mail->From = $webmaster_email;
$mail->FromName = "Mailback"; //este é o nome dinamico e que vai aparecer ao destinatario final
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("error_log"); // attachment
$mail->AddAttachment("ChangeLog.txt"); // attachment
$mail->CharSet	= "utf-8";
$mail->Encoding	= "quoted-printable";
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Isto é o titulo";
$mail->Body = "******* ***** ******,
Hoje foi um belo avanço nesta matéria "; //HTML Body
$mail->AltBody = "Body with papers"; //Text Body
if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "Message has been sent to $email";
} 
  
?>

Open in new window

Do you have this problem with other recipients also? Or only with Gmail... do you've access to the logfiles of the mailserver to see what response the gmail servers are giving you?

Personally i had an email deliverd to me a few times on another account because the sending mailserver "thought" it wasnt accepted by the receiving mailserver when in fact it was. That was solved due to a timeout issue at the time, which may not be the case here, but the logfiles should give you an indication.. or if possible, perhaps you could log the conversation between the 2 mailservers. For example with "recordio" if you're using daemontools.
This happening with other recepient's (I try two account's in gmail).
 I'm cruise with this situation, because sometimes they made the delivery correctly and other time they send a lot of the same e-mail.
In the beggining of the problem I think is because the server where script has been executed, and I try with other server and the problem continue.

So, The problem is not directly in the script, but in the gmail server.
Do you thing if we made some changes in the code, resolve the problem?
Have other ways to send e-mail with smtp of gmail?
It might be interesting to see the SMTP transcript. Try setting: $mail->SMTPDebug = true;
It's to put "$mail->SMTPDebug = true;" in email.php?
I attach the files contain the class.
Now I send the attach files
class.phpmailer.txt
class.smtp.txt
> put "$mail->SMTPDebug = true;" in email.php?

Yes, just add that line after creating the PHPMailer instance, but before you call send().
I put the line:
<?
require_once("class.phpmailer.php");

$mail=new PHPMailer();
$mail->SMTPDebug = true;
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
........

I made the test in two servers, and they just send "one" e-mail! That's good!
But before I change that line, after script execution, the browser show this text:'Message has been sent to numeroum@tagspedia.com'. Now the browser show thnis text:
==============================
SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "220 mx.google.com ESMTP 9sm3670111yxs.5 " SMTP -> get_lines(): $data is "220 mx.google.com ESMTP 9sm3670111yxs.5 " SMTP -> FROM SERVER: 220 mx.google.com ESMTP 9sm3670111yxs.5 SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "250-mx.google.com at your service, [209.190.85.202] " SMTP -> get_lines(): $data is "250-mx.google.com at your service, [209.190.85.202] " SMTP -> get_lines(): $data was "250-mx.google.com at your service, [209.190.85.202] " SMTP -> get_lines(): $str is "250-SIZE 35651584 " SMTP -> get_lines(): $data is "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 " SMTP -> get_lines(): $data was "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 " SMTP -> get_lines(): $str is "250-8BITMIME " SMTP -> get_lines(): $data is "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 250-8BITMIME " SMTP -> get_lines(): $data was "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 250-8BITMIME " SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN " SMTP -> get_lines(): $data is "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN " SMTP -> get_lines(): $data was "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN " SMTP -> get_lines(): $str is "250 ENHANCEDSTATUSCODES " SMTP -> get_lines(): $data is "250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN 250 ENHANCEDSTATUSCODES " SMTP -> FROM SERVER: 250-mx.google.com at your service, [209.190.85.202] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN 250 ENHANCEDSTATUSCODES SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 " SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6 " SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 " SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 " SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "235 2.7.0 Accepted " SMTP -> get_lines(): $data is "235 2.7.0 Accepted " SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "250 2.1.0 OK 9sm3670111yxs.5 " SMTP -> get_lines(): $data is "250 2.1.0 OK 9sm3670111yxs.5 " SMTP -> FROM SERVER: 250 2.1.0 OK 9sm3670111yxs.5 SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "250 2.1.5 OK 9sm3670111yxs.5 " SMTP -> get_lines(): $data is "250 2.1.5 OK 9sm3670111yxs.5 " SMTP -> FROM SERVER: 250 2.1.5 OK 9sm3670111yxs.5 SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "354 Go ahead 9sm3670111yxs.5 " SMTP -> get_lines(): $data is "354 Go ahead 9sm3670111yxs.5 " SMTP -> FROM SERVER: 354 Go ahead 9sm3670111yxs.5 SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "250 2.0.0 OK 1225058097 9sm3670111yxs.5 " SMTP -> get_lines(): $data is "250 2.0.0 OK 1225058097 9sm3670111yxs.5 " SMTP -> FROM SERVER: 250 2.0.0 OK 1225058097 9sm3670111yxs.5 SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "221 2.0.0 closing connection 9sm3670111yxs.5 " SMTP -> get_lines(): $data is "221 2.0.0 closing connection 9sm3670111yxs.5 " SMTP -> FROM SERVER: 221 2.0.0 closing connection 9sm3670111yxs.5 Message has been sent to numeroum@tagspedia.com
===================================================================
For my work is not a problem they show that text, but my costumers request some script like this one, is not good view that text in the browser!
But the most important, is the script work.

Do you thing I put the line in the right place?
I think you misunderstood what this is for - all that extra text is a dump of the conversation between your script and the mail server. Adding that line has caused that text to appear, and it's certainly not the kind of thing you should put on a production web server, but it is very useful when developing and debugging. So remove or comment out that line for your real site, but leave it in where you're trying to figure out this problem.
ASKER CERTIFIED SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Because this don't have any way to control the operation. I understand, but in computers sometimes have magic solutions, but not for this case.
The sensitive of google mail cause the system sometimes work well and others not, but the in most of the time the system work well.
Ok, thanks for your help.