j789
asked on
Send email with pdf attachment using php
Hi, can anyone assist. I'm trying to send an email with a pdf attachment using php. What would be the best approach as I have tried using php mail but I keep getting the following message - Warning: filesize(): stat failed...
Thanks.
Thanks.
PHPMailer will do it. http://code.google.com/a/apache-extras.org/p/phpmailer/wiki/PHPMailer
Better try phpMailer class to send attached email, ref. http://phpmailer.worxware.com/index.php?pg=tutorial#3
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you please give us a little more information about the exact issues? PHP filesize() would appear to be related not to the mail process, but to file creation. So a warning from that function would tell me to look elsewhere for the issues.
A tangential thought... Why send a PDF at all? If it's possible to send a link to a PDf instead, your bandwidth requirements will be much smaller and it won't clutter the client inbox. They can download a PDF with a single click if they want to receive it and store it.
Best regards, ~Ray
A tangential thought... Why send a PDF at all? If it's possible to send a link to a PDf instead, your bandwidth requirements will be much smaller and it won't clutter the client inbox. They can download a PDF with a single click if they want to receive it and store it.
Best regards, ~Ray
Open in new window