?>
添加多个附件正如上一节,添加多个附件是rasy与调用addAttachment了。在这个例子中,我会发送一个带有两个文本附件的电子邮件。
include(‘Mail.php’);
include(‘Mail/mime.php’);
// Constructing the email
$sender = “Leigh “; // Who your name and email address
$recipient = “Leigh “; // The Recipients name and email address
$subject = “Test Email”; // Subject for the email
$text = ‘This is a text message.’; // Text version of the email
$html = ‘
This is a html message
‘; // HTML version of the email
$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!”; // Content of the file
$file_name = “Hello text.txt”; // Name of the Attachment
$content_type = “text/plain”; // Content type of the file
$mime->addAttachment ($file, $content_type, $file_name, 0); // Add the attachment to the email
// Add a second attachment
$file = “Hello World! Again :)”; // Content of the file
$file_name = “Hello text 2.txt”; // Name of the Attachment
$content_type = “text/plain”; // Content type of the file
$mime->addAttachment ($file, $content_type, $file_name, 0); // Add the attachment to the email
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail =& Mail::factory(‘mail’);
$mail->send($recipient, $headers, $body);
?>