php mail带附件,Pear Mail 发送邮件带附件_PHP教程

?>

添加多个附件正如上一节,添加多个附件是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);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值