Universal Send email html or plain text php

后端 未结 2 1368
遥遥无期
遥遥无期 2021-01-29 15:45

Been there for days wraps over the fact that I can create a script that sends HTML mail template, and in case the user has a client who can not read HTML and plain text listing

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 16:42

    You should add html and plain text version of email called multipart/alternative in same email body:

    \n";
    
                    $headers .=  "To: ". $new_to ."\n";
    
                    $headers .= "Reply-To: \"". $from. "\" <" . $email . ">\r\n";
                    $headers .= "Return-Path: <". $email .">\r\n";
                    $headers .= "MIME-Version: 1.0\r\n";
                    $headers .= "Content-Type: multipart/alternative;\n boundary=" . $mime_boundary_header ;
                    $headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
                    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
                    $headers .= "\n--$boundary\n";
                    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                    $headers .= "Content-Transfer-Encoding:base64\r\n";
    $body = "
    
    --$mime_boundary
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    
    ". strip_tags($messageBody) ."
    
    --$mime_boundary
    Content-Type: text/html; charset=us-ascii
    Content-Transfer-Encoding:base64
    
    ". chunk_split(base64_encode($messageBody)) ."
    
    --$mime_boundary--";
    
    mail(null,$sub,$body,$headers,"-f".$email); 
    

提交回复
热议问题