附件怎么发送 php,发送带附件的PHP代码

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

一个简单的方法来发送带有附件的HTML电子邮件。

// Set who this goes to:

$to = array('Billy Bob','[email protected]');

// Give the message a subject:

$subject = 'Some subject';

// Set who this message is from:

$from = array("My Company","[email protected]");

// Create the header information:

$random_hash = md5(date('r',time()));

$mime_boundary = "==Multipart_Boundary_x{$random_hash}x";

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-Type: multipart/mixed; boundary="'.$mime_boundary.'"' . "\r\n";

$headers .= 'To: '.$to[0].' ' . "\r\n";

$headers .= 'From: '.$from[0].' ' . "\r\n";

// Build the message (can have HTML in it) message:

$message = 'This is an HTML message it comes with an attachment!'."\n\n".

// Do not edit this part of the message:

"--{$mime_boundary}\n" .

"Content-Type:text/html; charset=\"iso-8859-1\"\n" .

"Content-Transfer-Encoding: 7bit\n\n" .

$message . "\n\n";

// The image that you would like to send (filename only):

$name = 'PHPsnippets.jpg';

// The path to the image with the file name:

$fileatt = "images/".$name;

$fileatt_type = "application/octet-stream"; // File Type

// Filename that will be used for the file as the attachment

$fileatt_name = $name;

// Read the file attachment:

$file = fopen($fileatt,'rb');

$data = fread($file,filesize($fileatt));

fclose($file);

// Create sendable information

$data = chunk_split(base64_encode($data));

// Finalize the message with attachment

$message .= "--{$mime_boundary}\n" .

"Content-Type: {$fileatt_type};\n" .

" name=\"{$fileatt_name}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .

$data . "\n\n" .

"--{$mime_boundary}\n";

unset($data);

unset($file);

unset($fileatt);

unset($fileatt_type);

unset($fileatt_name);

// Send the message:

mail($to[1],$subject,$message,$headers);

?>

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

总结

以上是编程之家为你收集整理的发送带附件的PHP代码全部内容,希望文章能够帮你解决发送带附件的PHP代码所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值