Welcome Guest, Not a member yet? Register   Sign In
Broken html email?

Not sure when it broke... but i haven't been able to send an html email in some time. The email comes through as blank. Subject line reads ok. Text only email works fine. HTML fails. Thoughts?



- CI 3.1.6
- Not extending Mail library.

This is the test...
PHP Code:
->initialize(array('mailtype' => 'html'))
subject('Your Purchase Receipt')
message('<html><head></head><body><p>This is a test body</p></body></html>')

This is what my mail reader is showing me as the raw email body:
Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from mailserver.whereiam.com
by mailserver.whereiam.com with LMTP id ICE0A1JU/lkcQwAAjtiaIg
for <[email protected]>; Sat, 04 Nov 2017 19:59:14 -0400
Return-path: <[email protected]>
Envelope-to: [email protected]
Delivery-date: Sat, 04 Nov 2017 19:59:14 -0400
Received: from [xxx.xxx.xxx.xxx] (port=49603 helo=586589-www1.theserver.com)
by mailserver.whereiam.com with esmtp (Exim 4.89)
(envelope-from <[email protected]>)
id 1eB8LJ-0004Rz-2U
for [email protected]; Sat, 04 Nov 2017 19:59:13 -0400
Received: by 586589-www1.theserver.com (Postfix, from userid 48)
id 44592C3A2156; Sat,  4 Nov 2017 18:58:33 -0500 (CDT)
To: [email protected]
Subject: =?UTF-8?Q?Your=20Purchase=20Receip?==?UTF-8?Q?t?=
Date: Sat, 4 Nov 2017 23:58:33 +0000
From: "The Server" <[email protected]>
Reply-To: <[email protected]>
User-Agent: CodeIgniter
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_59fe5429412f7"
X-Spam-Status: No, score=1.1
X-Spam-Score: 11
X-Spam-Bar: +
X-Ham-Report: Spam detection software, running on the system "mailserver.whereiam.com",
has NOT identified this incoming email as spam.  The original
message has been attached to this so you can view it or label
similar future email.  If you have any questions, see
root\@localhost for details.

Content preview:  Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding:
   8bit This is a test body [...]

Content analysis details:   (1.1 points, 5.0 required)

 pts rule name              description
---- ---------------------- --------------------------------------------------
-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
                            [score: 0.0031]
 0.0 T_TVD_MIME_NO_HEADERS  BODY: No description available.
 1.0 KAM_LAZY_DOMAIN_SECURITY Sending domain does not have any
                            anti-forgery methods
 2.0 RDNS_NONE              Delivered to internal network by a host with no rDNS
 0.0 T_MIME_MALF            Malformed MIME: headers in body
X-Spam-Flag: NO

This is a multi-part message in MIME format.

Your email application may not support this format.


Content-Type: text/plain; charset=UTF-8

Content-Transfer-Encoding: 8bit

This is a test body


Content-Type: text/html; charset=UTF-8

Content-Transfer-Encoding: quoted-printable

=3Chtml=3E=3Chead=3E=3C/head=3E=3Cbody=3E=3Cp=3EThis is a test body=3C/p=3E=


(This post was last modified: 11-05-2017, 08:38 AM by SomeGuy.)

Figured out why it's breaking, not the fix.

PHP Code:
<?php defined('BASEPATH') OR die('No direct script access allowed.');

$config['protocol'] = 'mail'# production' === ENVIRONMENT ? 'smtp' : 'mail';

$config['smtp_crypto'] = 'tls';
$config['smtp_host'] = 'in-v3.mailjet.com';
$config['smtp_port'] = '587';
$config['smtp_user'] = '';
$config['smtp_pass'] = '';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "\n";

# This causes HTML emails to break
# Something to do with Email::_prep_quoted_printable()
# $config['newline'] = "\r\n"; 

Maybe someone could enlighten me.

Possible fix at: http://php.net/manual/en/function.quoted...php#115840 - I haven't investigated though.

I use CI's email class all the time, and it works fine. I always use "\r\n" for newline. I always use SMTP. There's nothing wrong with CI's email class, but if you insist, then try using Swiftmailer. Once I had an email problem, and the host was trying to tell me that it was a CI email class problem, so I switched to Swiftmailer to debug and the problem persisted. It was the host's problem. There is no mystery or magic here. Just use the email class as described in the docs and you should be good.

(This post was last modified: 11-05-2017, 10:05 AM by SomeGuy.)

I appreciate the "It works for me" suggestions - however, it's not all that helpful when it clearly doesn't work for me when specifying \r\n in the config file.

Thanks though?

Can you send to mailtrap?

I've never used mailtrap. The solution, at least in my case, was simple once diagnosed. It's seemingly an issue with PHP's (v5.6 I think) implementation of quoted_printable_encode(), assuming that my code was hitting the condition at system/libraries/Email.php:1516

I haven't dug deeper as it's fixed for now, at least for me.

PHP Code:
1512        // RFC 2045 specifies CRLF as "\r\n".
1513        // However, many developers choose to override that and violate
1514        // the RFC rules due to (apparently) a bug in MS Exchange,
1515        // which only works with "\n".
1516        if ($this->crlf === "\r\n")
1517        {
1518            return quoted_printable_encode($str);
1519        }

Theme © iAndrew 2016 - Forum software by © MyBB