Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

message sent twice

Posted on 2008-06-17
9
Medium Priority
?
642 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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 …

705 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