php邮件如何附件上传,如何在PHP中发送电子邮件附件

本文探讨了一封包含sendFiles.php文件和文本附件的电子邮件在编码转换后,文本内容丢失的问题。通过分析代码,发现CRLF修复附件问题的同时导致'Alogohasbeensen’tby'消失,解释了原因并提供了解决方案。
摘要由CSDN通过智能技术生成

// array with filenames to be sent as attachment

$files = array("sendFiles.php");

// email fields: to, from, subject, and so on

$to = "dfjdsoj@googlemail.com";

$from = "mail@mail.com";

$subject ="My subject";

$message = "A logo has been sen't by". $_SESSION['loggedin_business_name'];

$headers = "From: $from";

// boundary

$semi_rand = md5(time());

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

// headers for attachment

$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

// multipart boundary

$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";

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

// preparing attachments

for($x=0;$x

$file = fopen($files[$x],"rb");

$data = fread($file,filesize($files[$x]));

fclose($file);

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

$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .

"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .

"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";

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

}

// send

echo sizeof($files);

$ok = @mail($to, $subject, $message, $headers);

if ($ok) {

echo "

mail sent to $to!

";

} else {

echo "

mail could not be sent!

";

}

?>

我收到一封包含sendfiles.php的电子邮件,然后是一个文本文件ATT00424.txt.数量每次都在变化.发送到我的Gmail,没关系!很奇怪!

$files = array("sendFiles.php");

// email fields: to, from, subject, and so on

$to = "hdfiuhufsadhfu@yaho.com";

$from = "mail@mail.com";

$subject ="My subject";

$message = "A logo has been sen't by". $_POST['loggedin_business_name'];

$headers = "From: $from";

// boundary

$semi_rand = md5(time());

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

// headers for attachment

$headers .= "\r\nMIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\"";

// multipart boundary

$message = "This is a multi-part message in MIME format.\r\n" . "--{$mime_boundary}\r\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n" . $message . "\r\n";

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

// preparing attachments

for($x=0;$x

$file = fopen($files[$x],"rb");

$data = fread($file,filesize($files[$x]));

fclose($file);

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

$message .= "Content-Type: {\"application/octet-stream\"};\r\n" . " name=\"$files[$x]\"\r\n" .

"Content-Disposition: attachment;\r\n" . " filename=\"$files[$x]\"\r\n" .

"Content-Transfer-Encoding: base64\r\n" . $data . "\r\n";

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

}

在代码中添加CRLF修复了附件问题但是现在消息“A logo has sen’t by”消失了.为什么是这样?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值