Link to home
Start Free TrialLog in
Avatar of nzrubin
nzrubinFlag for New Zealand

asked on

message sent twice

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

Avatar of Matthew Kelly
Matthew Kelly
Flag of United States of America image

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>>");
Avatar of nzrubin

ASKER

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

Avatar of nzrubin

ASKER

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

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

Avatar of nzrubin

ASKER

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

I am unsure. There may be something in your logic that calls the section of code multiple times?
Do you understand that
if(!$mail->Send())
actually sends a copy of the message?

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

Avatar of nzrubin

ASKER

i didnt know about it.  why is that?
 it doesnt make sence!
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America 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