How to send an email attachment using PHP [duplicate]
Possible Duplicate:
Send email with attachments in PHP?
How can I send an email attachment using PHP without installing any thing and jus开发者_运维问答t using the mail() function?
The zend framework has a nice class to do this. It would require that you copy the framework to your server to access it.
http://framework.zend.com/
PHPMailer can use the native mail()
function:
<?php
require_once('PHPMailer_v5.1/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$mail->SetFrom($fromAddress, 'First Last');
$mail->AddReplyTo($replyToAddress, "First Last");
$mail->AddAddress($toAddress, "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!";
}
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
Read This Article for more information.
Need to use a multiplart/mixed MIME type and also base64_encode the attachment.
Check this link Mail() Email Attachment for details.
The attachments are included in the body of the message. It is probably a good idea to be familiar with MIME and the MIME RFCs. The link that Christopher Ickes and Brad gave will help with the implementation but the code glosses over the details that can help when debugging down the track.
精彩评论