In a php file i need to send 2 different emails to 2 different id's. It did not work when i used two variables like this shown below.
require 'PHPmailer/class.phpmailer.php';
/* First Email*/
$email = new PHPMailer();
$email->From = '[email protected]';
$email->FromName = 'My Webisite';
$email->Subject = 'Subject of first email';
$email->Body = 'Body of the message to first person';
$email->AddAddress( 'to first person' );
$file_to_attach = 'path of the file';
$email->AddAttachment( $file_to_attach, '' );
$email->Send();
/* Second Email*/
require 'PHPmailer/class.phpmailer.php';
$confirm = new PHPMailer();
$confirm-> From = '[email protected]';
$confirm-> FromName = 'Admin @ MyWebsite';
$confirm-> Subject = 'Subject of second email';
$confirm-> Body = 'Body of second email';
$confirm-> AddAddress('Email ID of second person');
$confirm->Send();
But if i use the same variable twice i will work as shown below
require 'PHPmailer/class.phpmailer.php';
/* First Email*/
$email = new PHPMailer();
/* Same as above*/
$file_to_attach = 'path of the file';
$email->AddAttachment( $file_to_attach, '' );
$email->Send();
/* Second Email*/
$email-> From = '[email protected]';
$email-> FromName = 'Admin @ MyWebsite';
$email-> Subject = 'Subject of second email';
$email-> Body = 'Body of second email';
$email-> AddAddress('Email ID of second person');
$email->Send();
But the problem is it is sending the attachment to both the email ids. Please help me how do i not send the attachment to second id.