Trying to attach and attachement
Posted: Wed Jul 22, 2009 12:55 pm
I can’t seem to figure out how to get an attachment to send from this script below. The mail will send ok and I have a folder called ‘files’ where I upload the PDF’s, word docs etc to have attached to the script but I cannot work out how to pass these to this script. I think I should be writing a path to $file_name = "files/somefile.pdf"; but can’t be sure.
Any help would be great
Thanks
Any help would be great
Thanks
Code: Select all
include('Mail.php');
include('Mail/mime.php');
$sender = "Joe soap <info@me.com>";
$recipient = "Crazy<info@you.com>";
$subject = "Test Email";
$text = 'This is a test message.';
$html = '<html><body><p>This is a html message</p></body></html>'; $crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Add an attachment
$file = "Hello World!";
$file_name = "files/somefile.pdf";
$content_type = "Application/pdf";
$mime->addAttachment ($file, $content_type, $file_name, 0);
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail =& Mail::factory('mail');
$mail->send($recipient, $headers, $body)