phpmailer sending out 2 emails


mikecam3
Asked:
2013-07-02 7:47 pm EST

Hits: 3,987
User: ctarfq5

I have a form that submits information to a php file. The php takes the information and formats it and sends it off in an email. I am using phpmailer. The initial email is perfect. The second and sometimes third that comes after with no submission on my part is a problem. What is causing the second email, with no form information to be sent?

I am not comfortable posting code, as it has password information. You can assume a classic phpmailer code. I am sending the email to multiple people and with an attachments.

Is there a phpmailer setting that I need to send, or a way to hinder the second email after the first is sent?

Thanks.

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

Arn
Staff
17,351 Points
2013-07-02 9:01 pm EST
Hello Mikecam3,

I'm sorry to hear about the problem with the emails. I went through the server to make sure that there was no error that I could find that's causing the problem. There's no visible issue being reported to the error logs. And there is no record of the issue occurring on other accounts.

This is a programmatic issue - most likely with phpmailer. I know you're looking for PHPmail setting(s) advice here, but you probably need to add some debugging code so you can determine what's causing the multiple messages since it doesn't appear be server related. I looked for something like this on the web. Check out this link: PHP Mail duplicates - though you did not indicate if the subsequent messages are actually duplicates.

Try their suggestion, as it may lead to the answer you're searching for. If you continue to have the problem, we can try to review it again. Any detail at all would help us, so if you could please send more information (e.g. the message was duplicated or this is the URL I'm using) then we would happy to help.

Thanks for you patience, please let us know if you require any further assistance!

Regards,
Arnel C.

You must login before you can post a comment about this answer.

After a long search, with new keywords you provided...Thanks.

The solution, if anyone needs it, is as follows for phpmailer:
Make sure you have these lines to set variables in phpmailer. (Middle line was the key)

$mail1 = new PHPMailer();
$mail1->Sender = "your_email@y.com";
$mail1->Username = "your_email@y.com";
mikecam3
38 Points
2013-07-03 11:16 am EST
I also added the folllowing before and after the email send: (not sure the usefulness of it)

$mail1->ClearAddresses();
mikecam3
38 Points
2013-07-03 11:19 am EST
I take it back, it only helped for a couple emails.

Here is the clean code:
require_once("public_html/Mailer/PHPMailer_5.2.0/class.phpmailer.php");

$mail1 = new PHPMailer();

$mail1->ClearAddresses();
$mail1->Sender = "you@y.com";
$mail1->IsSMTP();
$mail1->Host = "localhost";
$mail1->SMTPAuth = true;
$mail1->Username = "you@y.com";
$mail1->Password = "password";

$mail1->From = "you@y.com";
$mail1->FromName = "Builder";
$mail1->AddReplyTo( "you@y.com", "DO NOT REPLY" );

$mail1->AddAddress("Person1.com", "John Doe");
$mail1->AddCC("Person2.com", "Josh Doe");
$mail1->AddCC("Person3.com", "Jim Doe");


for($i=0;$i<13;$i++) //Adding of Salesman, minus John Doe
{
if ($Salesman1==$arrNames1[$i])
{
$mail1->AddCC($arrAdd1[$i], $arrNames1[$i]);
break;
}
}

if ($Eng!="Josh Doe") //Adding of Engineer Minus Josh
{
for($i=0;$i<13;$i++)
if ($Eng==$arrNames1[$i])
{
$mail1->AddCC($arrAdd1[$i], $arrNames1[$i]);
break;
}
}

for($i=0;$i<13;$i++) //Adding of rest minus Engineer/Sales
{
if ($username1==$arrNames1[$i] AND $username1 != $Salesman1 AND $username1 != $Eng)
{
$mail1->AddCC($arrAdd1[$i], $arrNames1[$i]);
break;
}

}

$mail1->WordWrap = 50;

for($i=0;$i<10;$i++)
{
$path1="address/address";
$AtTemp1=$path1.$dName1[$i];
if ($AtTemp1 !="address/address")
{
$mail1->AddAttachment($AtTemp1);
}
}
//}
//}
$mail1->IsHTML(true);
$mail1->Subject = "test email";
$mail1->Body = $message1;

if(!$mail1->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail1->ErrorInfo;
exit;
}
$mail1->ClearAddresses();
mikecam3
38 Points
2013-07-03 11:43 am EST
Hello Mikecam3,

I spoke with our manager who does a lot of PHP work. He said that in looking at your code he sees several loops. The addition of the addresses for the multiple emails is coming from one of the loops. He suggested that you comment out the loops one by one and test each time. This way you can isolate where the additional addresses are being added.

I hope this helps! Sorry for the ongoing problem!

Regards,
Arnel C.
Arn
17,351 Points
Staff
2013-07-03 12:08 pm EST
Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!