Hi ,I need my php program to send an email with multiple attachments.
The following code only sends one attatchment even though I am attaching 2 files.
Please advise.
The following code only sends one attatchment even though I am attaching 2 files.
Code:
<?php
require_once "Mail.php"; // PEAR Mail package
require_once ('Mail/mime.php'); // PEAR Mail_Mime packge
$thedate="20100907";
$from = "thinus <167677690@nwu.ac.za>";
$to = "thinus <1236767690@nwu.ac.za>";
$subject = 'Test mime message with an attachment';
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$text = 'Text version of email'; // text and html versions of email.
$html = '<html><body>HTML version of email. <strong>This should be bold</strong></body></html>';
$file1 = "C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".$thedate."/"."TRI_FP_difference_".$thedate.".pdf"; // attachment
$file2 ="C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".date("Ymd",strtotime("+1 days",$thedate))."/"."TRI_FP_difference_".date("Ymd",strtotime("+1 days",$thedate)).".pdf";
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file1,'pdf');
$mime->addAttachment($file2,'pdf');
$body = $mime->get();
$headers = $mime->headers($headers);
$host = "scanmail.nwu.ac.za";
$username = "bwi67e";
$password = "b53$";
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
'username' => $username,'password' => $password));
////////////////////////////////////////
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
}
?>
Please advise.
Comment