Solved

message sent twice

Posted on 2008-06-17
9
634 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

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…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

632 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