theplau
theplau

Reputation: 980

How do I fix annoying quoted-printable emails sent with PHP?

I am sending emails like this:

$message = "Hello<br/>Something else here.<br/>Bye!";
$html_msg = '<html><head>
             <meta http-equiv="content-type" content="text/html; charset=utf-8">
             </head><body bgcolor="#FFFFFF" text="#000000">
             '.$message.'
             </body>
             </html>';

$header = "Date: " . $mail_date . "\n".
          "Return-Path: " . $from_email . "\n".
          "To: " . $to . "\n".
          "From: Me <[email protected]>\n".
          "Subject: " . $subject . "\n".
          "MIME-Version: 1.0\n".
          "Content-Transfer-Encoding: 7bit\n".
          sprintf("Content-Type: %s; charset=\"%s\"","text/html","utf-8")."\n\n";

$output = sprintf("%s -oi -t", "/usr/sbin/sendmail");

    if(!@$mail = popen($output, "w")) {
                echo "Error!";
    }

    fputs($mail, $header);
    fputs($mail, $html_msg);

    $result = pclose($mail) >> 8 & 0xFF;

    if($result != 0) {
                echo "Error!";
    }

Now, it executes correctly but when I check the HTML code of the email received, it's full of quoted-printable content like:

<html><head>
=09=09=09=09=09=09=09 <meta http-equiv=3D"content-type" content=3D"text/htm=

How do I fix this?

Upvotes: 2

Views: 2074

Answers (1)

Anton
Anton

Reputation: 4052

=09 is a tab symbol.

In your code you must be using tabs to create a spacing in front of the closing head tag and these tabs show up as =09

$html_msg = '<html><head>
             <meta http-equiv="content-type" content="text/html; charset=utf-8">

Try to rewrite as:

$html_msg = '<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

Note that there in no leading spaces/tabs in front of second line.

Upvotes: 2

Related Questions