user1537415
user1537415

Reputation:

PHPMailer not sending mail

I'm trying to send an order confirmation and also notify the seller about a user purchase. However, PHPMailer only sends the first email. Here's quick and dirty:

$bodytext = 'Mail.';
$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'Sender';
$email->Subject   = 'Subject';
$email->Body      = $bodytext;
$email->AddAddress($_REQUEST['sahkoposti']);
$email->AddAttachment($path, 'kuitti'.$ordernumber.'.pdf');
return $email->Send();
?>

<?php

//send message to seller


$bodytext = 'Mail.';
$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'Sender';
$email->Subject   = 'Tilaus vastaanotettu';
$email->Body      = $bodytext;
$email->AddAddress("[email protected]");
$email->AddAttachment($path, 'kuitti'.$ordernumber.'.pdf');
return $email->Send();
?>

Is it even possible to send multiple emails from one script?

Upvotes: 0

Views: 520

Answers (2)

The second email does not get executed because you are returning right after sending the first email, you should change:

return $email->Send();

for this:

$email->Send();

Upvotes: 0

Zathrus Writer
Zathrus Writer

Reputation: 4331

It is possible, however you're using return in the first statement, which will stop execution of the function. Remove the first return (just use $email->Send();) and it should work.

Upvotes: 2

Related Questions