send PHP mail with Content-Type: multipart/alternative

后端 未结 4 1416
抹茶落季
抹茶落季 2020-12-11 19:37

I am trying to send a multipart mail that contains both html and plain text. This is also one of the ways to get through spam filters and to allow more people to read the ma

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 19:43

    The line:

    $header .= 'Content-type: multipart/alternative;boundary=$boundary '."\n";
    

    Has the wrong quotes, so $boundary won't be expanded. Change to:

    $header .= "Content-type: multipart/alternative;boundary=$boundary\n";
    

    And like I said in the comments, in the message headers and the content section headers you should be using \r\n as the line break since that's what is defined in the RFC. Most MTAs will allow simply \n, but some will choke on the message, and some spam filters will count every RFC violation as a point towards your spam score.

    Using something like PHPMailer is a much better option because it formats everything perfectly by default, and abides by just about every single obscure, boring RFC.

提交回复
热议问题