Solved

message sent twice

Posted on 2008-06-17
9
622 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 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