Инструменты пользователя

Инструменты сайта


programming:php:mail-attach

Отправка писем с аттачем

$f = fopen($filename, "rb");
$uniq = strtoupper(uniqid(time()));
$head = "From: $from\n";
$head .= "Mime-Version: 1.0\n";
$head .= "Content-Type:multipart/mixed;";
$head .= "boundary=\"----------".$uniq."\"\n\n";
$body = "------------".$uniq."\nContent-Type:text/html; charset=utf-8\n";
$body .= "Content-Transfer-Encoding: 8bit\n\n$text\n\n";
$body .= "------------".$uniq."\n";
$body .= "Content-Type: application/octet-stream;";
$body .= "name=\"".basename($filename)."\"\n";
$body .= "Content-Transfer-Encoding:base64\n";
$body .= "Content-Disposition:attachment;";
$body .= "filename=\"".basename($filename)."\"\n\n";
$body .= chunk_split(base64_encode(fread($f, filesize($filename))))."\n";

mail($email_to, '=?UTF-8?B?'.base64_encode($email_subj).'?=', $email_body, 'From: robot@site.com' . "\n" . 'Content-type: text/html; charset=utf-8' . "\n");
programming/php/mail-attach.txt · Последнее изменение: 2017/03/27 11:26 — artur

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki