0

Как можно отправить через mail() php письмо html, если html код символов 900-1500?

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

в $text='длинный html код '

4
  • И в чём проблема?
    – Alexey Ten
    20 сен 2016 в 7:27
  • в переменную не помешается весь код а делать 30 переменных как-то не хочется
    – Aslero
    20 сен 2016 в 7:32
  • 2
    Что значит «не помещается код»? Вам неудобно писать его в одну строку? В PHP есть heredoc
    – Alexey Ten
    20 сен 2016 в 7:34
  • Может проще html вынести в отдельный файл, и загружать его в переменную перед функцией mail? $text = file_get_contents('./message_file.html');
    – Bookin
    20 сен 2016 в 9:44

1 ответ 1

1

Вот вызов метода

$file = false;
$email = "email";
$theme = "theme";
$body = "body";

SendMail(array($email, $theme, $body), null, 'text/html', $file);

и сам метод

function SendMail ($letter, $data = '', $letter_type = 'text/plain', &$file = false) 
{   
    $is_file = false;

    $mailheaders = "From: DEMO<demo@demo.com>";     

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";                             
    $mailheaders .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";    

    $body = $letter[2];
    if (is_array($data)) {
        while (list($from, $to) = each($data)) {
            $body = str_replace($from, $to, $body);
        }
    }                   

    $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: $letter_type; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $body . "\n\n";
    $message .= "--{$mime_boundary}\n";

    if($file !== false) {
        if(@is_file($file[0])) {                        
            $handler = fopen($file[0], "rb");               
            if($handler !== false) {
                $fdata = fread($handler, filesize($file[0]));
                fclose($handler);
                $is_file = true;
            }
        } else {
            $fdata = $file[0];
            $is_file = true;
        }

        if($is_file) {          
            $fdata = chunk_split(base64_encode($fdata));
            $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"".$file[1]."\"\n" . 
            "Content-Disposition: attachment;\n" . " filename=\"".$file[1]."\"\n" . 
            "Content-Transfer-Encoding: base64\n\n" . $fdata . "\n\n";
            $message .= "--{$mime_boundary}\n";
        }
    }       

    mail ($letter[0], $letter[1], $message, $mailheaders);
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.