4

How to turn this into a plain text email?

 $bound_text=md5(uniqid(time()));
    $headers.="MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$bound_text\"\r\n";

    $message="--PHP-mixed-$bound_text\r\n"      
                ."Content-Type: text/html; charset=\"utf-8\"\r\n"
                ."Content-Transfer-Encoding: 7bit\r\n\r\n"  
                ."<html><head></head><body>"
                ."<div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\">$text_message</div></body></html>\r\n\r\n"  
                ."--PHP-mixed-$bound_text\r\n"  
                ."Content-Transfer-Encoding: base64\r\n"
                ."Content-Disposition: attachment; filename=\"$attachment\"\r\n"
    ."Content-Type: image/jpeg; name=\"$attachment\"\r\n\r\n"
     .chunk_split($file)
            ."\r\n\r\n"
                ."--PHP-mixed-$bound_text--\r\n\r\n";

    }

Is it just removing the HTML part and changing text/html into text/plain?

Tom
  • 5,588
  • 20
  • 77
  • 129
  • 4
    Probably. But have you considered using [PHPMailer or Swiftmailer](http://stackoverflow.com/questions/303783/phpmailer-vs-swiftmailer) for not having to micromanage things like that? – mario Feb 01 '12 at 11:42
  • For now I need to go with the posted code but thanks for the suggestion. – Tom Feb 01 '12 at 11:54
  • If you are sure that `$text_message` contains no HTML markup itself, then you're probably safe. Otherwise you may need to do some tidying up of that variable (e.g. `'
    '` -> `"\n"`, strip_tags)
    – cmbuckley Feb 01 '12 at 14:40

1 Answers1

15

Removing the HTML should do the trick but you'll probably want to change the content-type to text/plain as well:

."Content-Type: text/plain; charset=\"utf-8\"\r\n"

(I would have let a comment suffice but I can't post comments yet :))

h00ligan
  • 1,471
  • 9
  • 17