Solved

message sent twice

Posted on 2008-06-17
9
624 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Query 5 43
Unwanted output from my query 5 40
warning code: class php incomplete message 6 28
Make checkboxes execute queries on click 8 31
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
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 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…

763 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