php如何发送两封不同的邮件,如何附加两个或多个文件并使用PHP发送邮件

 <?phpif ($_POST) {

for($i=0; $i 

$ftype[]       = $_FILES['csv_file']['type'][$i];

$fname[]       = $_FILES['csv_file']['name'][$i];

}

// array with filenames to be sent as attachment

$files = $fname;

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

$to = "example@gmail.com";

$from = "example@gmail.com";

$subject ="My subject";

$message = "My message";

$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

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

if ($ok) {

echo "

mail sent to $to!

";

} else {

echo "

mail could not be sent!

";

} }?>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值