php邮件自动下载附件,在php邮件中自动附加文件 (Auto attach file in php mail)

You should use one of the classes built for that, for example PEAR Mail.

For a bit more explanation, assuming we use just a plain text UTF8 content with the PDF file.

uniqboundary should be replace by some sort of unique string

$fileType is the MIME type of your file

Here the code :

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

.'Content-Type: multipart/related; boundary="--uniqboundary"'."\r\n";

$body = '--uniqboundary."\r\n".

.'Content-Type: text/plain; charset=utf-8'."\r\n"

.'Content-Transfer-Encoding: 8bit'."\r\n\r\n"

.$text

.'--uniqboundary'."\r\n"

.'Content-Type: '.$fileType.'; name="'.basename($filename).'"'."\r\n"

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

.'Content-Disposition: attachment; filename="'.basename($filename).'"'."\r\n\r\n";

$lineSize = filesize($filename) + 1;

$f = fopen($filename, 'r');

$chunks[] = chunk_split(base64_encode(fread($f, $lineSize)));

fclose($f);

$body .= implode("\r\n", $chunks)

.'--uniqboundary--'."\r\n";

mail($to, $subject, $body, $headers);

It should work.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值