Solved

message sent twice

Posted on 2008-06-17
9
615 Views
Last Modified: 2008-06-20
hello guys
i use PHP mailer class with attachments the message goes twice (person receive two the same emails in the same time) (BCC as well receive two emails)

any ideas please?
if ($_POST['submit'])

		{

//// email with attachments		

require '../../../phpMailer/class.phpmailer.php';

$mail = new PHPMailer();

$mail->Subject = $_POST['subject'];

$mail->From = $_POST['from'];

$mail->FromName = $_POST['fromName'];

$mail->Body = $_POST['msg'];

$mail->AddAddress($_POST['to'],$_POST['toName']);

$mail->AddBCC($_POST['bcc']);

foreach ($pdf_name as $k)

{

$mail->AddAttachment("upload/$k");

}

$mail->Send();

Open in new window

0
Comment
Question by:nzrubin
  • 4
  • 3
  • 2
9 Comments
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 21809268
You may be confusing AddAddress with AddReplyTo.

The AddAddress should only have emails, but it looks like you also put in the 'toName' in it.

See the example below:

$mail->AddAddress("<<email address to>>");
$mail->AddReplyTo("<<email address from>>","<<email name from>>");
0
 
LVL 4

Author Comment

by:nzrubin
ID: 21809668
look
this still does two emails


require '../../../phpMailer/class.phpmailer.php';

$mail = new PHPMailer();

$mail->Subject = "this is the subject";

$mail->From = "v-w-v@yandex.ru";

$mail->FromName = "axo_vlad";

$mail->Body = "hello it is the message";

$mail->AddAddress("nz.vlad@gmail.com"); 

$mail->AddBCC("vlad@axo.cc");

$mail->Send();

Open in new window

0
 
LVL 4

Author Comment

by:nzrubin
ID: 21809672
but this makes 4!!!!
without BBC stroke the code produces 4 emails!!

require '../../../phpMailer/class.phpmailer.php';

$mail = new PHPMailer();

$mail->Subject = "this is the subject";

$mail->From = "v-w-v@yandex.ru";

$mail->FromName = "axo_vlad";

$mail->Body = "hello it is the message";

$mail->AddAddress("nz.vlad@gmail.com"); 
 

$mail->Send();

Open in new window

0
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 21809698
Try just doing this (I tested this config before):
<?php

 

require("class.phpmailer.php");

 

$mail = new PHPMailer();

 

$mail->IsSMTP(); // send via SMTP

$mail->Host     = "<<smtpserver>>:<<stmpport>>"; // SMTP servers

$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "<<uname>>"; // SMTP username

$mail->Password = "<<pword>>"; // SMTP password

$mail->From = "<<email address from>>";

$mail->FromName = "<<email name from>>";

$mail->AddAddress("<<email address to>>"); 

$mail->AddReplyTo("<<email address from>>","<<email name from>>");

$mail->WordWrap = 50; // set word wrap

$mail->IsHTML(true); // send as HTML

$mail->Subject  =  "Subject";

$mail->Body     =  "Body text";

$mail->AltBody  =  $mail->Body;

        

$mail->Send();

 

?>

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 4

Author Comment

by:nzrubin
ID: 21809789
i found the reason

after i removied checking script (see below) i started receive just one email as it needs to be...

why it can be so? it is interesting...


if(!$mail->Send())

{

   echo '<div align=\"center\" class=\"div\" style=\"margin-top:60px\">

		Message was not sent try again please

		</div>';

   echo 'Mailer error: ' . $mail->ErrorInfo;

}

else

{

//do whatever

}

Open in new window

0
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 21809821
I am unsure. There may be something in your logic that calls the section of code multiple times?
0
 
LVL 19

Expert Comment

by:Michael701
ID: 21810075
Do you understand that
if(!$mail->Send())
actually sends a copy of the message?

Sounds like you also have (had) another
$mail->Send();

0
 
LVL 4

Author Comment

by:nzrubin
ID: 21810281
i didnt know about it.  why is that?
 it doesnt make sence!
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 50 total points
ID: 21812639
By calling the SEND function within the if statement, doesn't mean Did the mail get sent. It means Send the mail and return the status.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now