Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Emails not displaying correctly. Suspected Email Function issue.


Go to End


3 Posts   2321 Views

Avatar
Dallby

Community Member, 1 Post

17 November 2016 at 4:03pm

Edited: 17/11/2016 4:04pm

Hi folks,

I'm trying to send a notification email (HTML), after an enquiry/contact form is submitted. There seems to be an issue with the Email Function.

Here is a screenshot of the issue I'm experiencing (I've hidden my email address, and other identifying/sensitive information.):

What I've learned/tried so far:

  • The email is being sent as a "multi-part" message. It sends some of it as plain text and some of it as HTML. (See below for code that fires the email function)
  • I have set the character type in the email template.
  • I have tried sending an HTML email from the standard php mail() function, and HTML content is sending fine. Which leads me to believe it may be something to do with the template rendering

Here is the raw source from the email message when I use the Silverstripe function:

Return-Path: <REMOVED FOR PRIVACY>
Delivered-To: REMOVED FOR PRIVACY
Received: (qmail 17022 invoked by uid 399); 17 Nov 2016 01:10:11 -0000
Received: from unknown (HELO nix36.qnetau.com) (202.146.215.18)
  by REMOVED FOR PRIVACY with ESMTP; 17 Nov 2016 01:10:11 -0000
X-Originating-IP: 202.146.215.18
Received: by REMOVED FOR PRIVACY (Postfix, from userid 642)
	id 63D78B3A; Thu, 17 Nov 2016 01:10:11 +0000 (UTC)
To: REMOVED FOR PRIVACY
Subject: =?UTF-8?B??=
X-PHP-Originating-Script: 642:Mailer.php
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_NextPart_176699263819"
Content-Transfer-Encoding: 7bit
From: REMOVED FOR PRIVACY
X-Mailer: SilverStripe Mailer - version 2006.06.21 (Sent from "REMOVED FOR PRIVACY")
X-Priority: 3
X-SilverStripeSite: mysite
Message-Id: <20161117011011.63D78B3A@REMOVED FOR PRIVACY>
Date: Thu, 17 Nov 2016 01:10:11 +0000 (UTC)


This is a multi-part message in MIME format.

------=_NextPart_176699263819
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

TESTING BASE EMAIL TEMPLATE

------=_NextPart_176699263819
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org=
/TR/xhtml1/DTD/xhtml1-strict.dtd">=0A<html xmlns=3D"http://www.w3.org/1999/=
xhtml" xmlns=3D"http://www.w3.org/1999/xhtml">=0A    <head>=0A        <meta=
 http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" />=0A  =
      <meta name=3D"viewport" content=3D"width=3Ddevice-width" />=0A    </h=
ead>=0A    <body style=3D"width: 100% !important; -webkit-text-size-adjust:=
 100%; -ms-text-size-adjust: 100%; color: #6c6e6d; font-family: 'Helvetica'=
, 'Arial', sans-serif; font-weight: normal; text-align: left; line-height: =
16px; font-size: 12px; background: #dbdbdb; margin: 0; padding: 0;" bgcolor=
=3D"#dbdbdb">=0A        <style type=3D"text/css">=0A            a:hover {=
=0A                color: #2795b6 !important;=0A            }=0A           =
 a:active {=0A                color: #2795b6 !important;=0A            }=0A=
            a:visited {=0A                color: #2ba6cb !important;=0A    =
        }=0A            h1 a:active {=0A                color: #2ba6cb !imp=
ortant;=0A            }=0A            h2 a:active {=0A                color=
: #2ba6cb !important;=0A            }=0A            h3 a:active {=0A       =
         color: #2ba6cb !important;=0A            }=0A            h4 a:acti=
ve {=0A                color: #2ba6cb !important;=0A            }=0A       =
     h5 a:active {=0A                color: #2ba6cb !important;=0A         =
   }=0A            h6 a:active {=0A                color: #2ba6cb !importan=
t;=0A            }=0A            h1 a:visited {=0A                color: #2=
ba6cb !important;=0A            }=0A            h2 a:visited {=0A          =
      color: #2ba6cb !important;=0A            }=0A            h3 a:visited=
 {=0A                color: #2ba6cb !important;=0A            }=0A         =
   h4 a:visited {=0A                color: #2ba6cb !important;=0A          =
  }=0A            h5 a:visited {=0A                color: #2ba6cb !importan=
t;=0A            }=0A            h6 a:visited {=0A                color: #2=
ba6cb !important;=0A            }=0A            table.button:hover td {=0A =
               background: #2795b6 !important;=0A            }=0A          =
  table.button:visited td {=0A                background: #2795b6 !importan=
t;=0A            }=0A            table.button:active td {=0A               =
 background: #2795b6 !important;=0A            }=0A            table.button=
:hover td a {=0A                color: #fff !important;=0A            }=0A =
           table.button:visited td a {=0A                color: #fff !impor=
tant;=0A            }=0A            table.button:active td a {=0A          =
      color: #fff !important;=0A            }=0A            table.button:ho=
ver td {=0A                background: #2795b6 !important;=0A            }=
=0A            table.tiny-button:hover td {=0A                background: #=
2795b6 !important;=0A            }=0A            table.small-button:hover t=
d {=0A                background: #2795b6 !important;=0A            }=0A   =
         table.medium-button:hover td {=0A                background: #2795=
b6 !important;=0A            }=0A            table.large-button:hover td {=
=0A                background: #2795b6 !important;=0A            }=0A      =
      table.button:hover td a {=0A                color: #ffffff !important=
;=0A            }=0A            table.button:active td a {=0A              =
  color: #ffffff !important;=0A            }=0A            table.button td =
a:visited {=0A                color: #ffffff !important;=0A            }=0A=
            table.tiny-button:hover td a {=0A                color: #ffffff=
 !important;=0A            }=0A            table.tiny-button:active td a {=
=0A                color: #ffffff !important;=0A            }=0A           =
 table.tiny-button td a:visited {=0A                color: #ffffff !importa=
nt;=0A            }=0A            table.small-button:hover td a {=0A       =
         color: #ffffff !important;=0A            }=0A            table.sma=
ll-button:active td a {=0A                color: #ffffff !important;=0A    =
        }=0A            table.small-button td a:visited {=0A               =
 color: #ffffff !important;=0A            }=0A            table.medium-butt=
on:hover td a {=0A                color: #ffffff !important;=0A            =
}=0A            table.medium-button:active td a {=0A                color: =
#ffffff !important;=0A            }=0A            table.medium-button td a:=
visited {=0A                color: #ffffff !important;=0A            }=0A  =
          table.large-button:hover td a {=0A                color: #ffffff =
!important;=0A            }=0A            table.large-button:active td a {=
=0A                color: #ffffff !important;=0A            }=0A           =
 table.large-button td a:visited {=0A                color: #ffffff !import=
ant;=0A            }=0A            table.secondary:hover td {=0A           =
     background: #d0d0d0 !important; color: #555;=0A            }=0A       =
     table.secondary:hover td a {=0A                color: #555 !important;=
=0A            }=0A            table.secondary td a:visited {=0A           =
     color: #555 !important;=0A            }=0A            table.secondary:=
active td a {=0A                color: #555 !important;=0A            }=0A =
           table.success:hover td {=0A                background: #457a1a !=
important;=0A            }=0A            table.alert:hover td {=0A         =
       background: #970b0e !important;=0A            }=0A            a:hove=
r {=0A                color: black !important;=0A            }=0A          =
  @media only screen and (max-width: 600px) {=0A                table[class=
=3D"body"] img {=0A                    width: auto !important; height: auto=
 !important;=0A                }=0A                table[class=3D"body"] ce=
nter {=0A                    min-width: 0 !important;=0A                }=
=0A                table[class=3D"body"] .container {=0A                   =
 width: 95% !important;=0A                }=0A                table[class=
=3D"body"] .row {=0A                    width: 100% !important; display: bl=
ock !important;=0A                }=0A                table[class=3D"body"]=
 .wrapper {=0A                    display: block !important; padding-right:=
 0 !important;=0A                }=0A                table[class=3D"body"] =
.columns {=0A                    table-layout: fixed !important;=0A        =
            float: none !important;=0A                    width: 100% !impo=
rtant;=0A                    padding-right: 0px !important;=0A             =
       padding-left: 0px !important;=0A                    display: block !=
important;=0A                }=0A                table[class=3D"body"] .col=
umn {=0A                    table-layout: fixed !important; float: none !im=
portant; width: 100% !important; padding-right: 0px !important; padding-lef=
t: 0px !important; display: block !important;=0A                }=0A       =
         table[class=3D"body"] .wrapper.first .columns {=0A                =
    display: table !important;=0A                }=0A                table[=
class=3D"body"] .wrapper.first .column {=0A                    display: tab=
le !important;=0A                }=0A                table[class=3D"body"] =
table.columns td {=0A                    width: 100% !important;=0A        =
        }=0A                table[class=3D"body"] table.column td {=0A     =
               width: 100% !important;=0A                }=0A              =
  table[class=3D"body"] td.offset-by-one {=0A                    padding-le=
ft: 0 !important;=0A                }=0A                table[class=3D"body=
"] td.offset-by-two {=0A                    padding-left: 0 !important;=0A =
               }=0A                table[class=3D"body"] td.offset-by-three=
 {=0A                    padding-left: 0 !important;=0A                }=0A=
                table[class=3D"body"] td.offset-by-four {=0A               =
     padding-left: 0 !important;=0A                }=0A                tabl=
e[class=3D"body"] td.offset-by-five {=0A                    padding-left: 0=
 !important;=0A                }=0A                table[class=3D"body"] td=
.offset-by-six {=0A                    padding-left: 0 !important;=0A      =
          }=0A                table[class=3D"body"] td.offset-by-seven {=0A=
                    padding-left: 0 !important;=0A                }=0A     =
           table[class=3D"body"] td.offset-by-eight {=0A                   =
 padding-left: 0 !important;=0A                }=0A                table[cl=
ass=3D"body"] td.offset-by-nine {=0A                    padding-left: 0 !im=
portant;=0A                }=0A                table[class=3D"body"] td.off=
set-by-ten {=0A                    padding-left: 0 !important;=0A          =
      }=0A                table[class=3D"body"] td.offset-by-eleven {=0A   =
                 padding-left: 0 !important;=0A                }=0A        =
        table[class=3D"body"] .expander {=0A                    width: 9999=
px !important;=0A                }=0A                table[class=3D"body"] =
.right-text-pad {=0A                    padding-left: 10px !important;=0A  =
              }=0A                table[class=3D"body"] .text-pad-right {=
=0A                    padding-left: 10px !important;=0A                }=
=0A                table[class=3D"body"] .left-text-pad {=0A               =
     padding-right: 10px !important;=0A                }=0A                =
table[class=3D"body"] .text-pad-left {=0A                    padding-right:=
 10px !important;=0A                }=0A                table[class=3D"body=
"] .hide-for-small {=0A                    display: none !important;=0A    =
            }=0A                table[class=3D"body"] .show-for-desktop {=
=0A                    display: none !important;=0A                }=0A    =
            table[class=3D"body"] .show-for-small {=0A                    d=
isplay: inherit !important;=0A                }=0A                table[cla=
ss=3D"body"] .hide-for-desktop {=0A                    display: inherit !im=
portant;=0A                }=0A                table[class=3D"body"] .right=
-text-pad {=0A                    padding-left: 10px !important;=0A        =
        }=0A                table[class=3D"body"] .left-text-pad {=0A      =
              padding-right: 10px !important;=0A                }=0A       =
     }=0A        </style>=0A        =0A        <table class=3D"container" s=
tyle=3D"border-spacing: 0; border-collapse: collapse; vertical-align: top; =
text-align: inherit; width: 580px; background: white; margin: 0 auto; paddi=
ng: 0;" bgcolor=3D"white">=0A            <tr style=3D"vertical-align: top; =
text-align: left; padding: 0;" align=3D"left">=0A                <td style=
=3D"word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyph=
ens: auto; border-collapse: collapse !important; vertical-align: top; text-=
align: left; padding: 0;" align=3D"left" valign=3D"top">=0A=0A             =
       <table class=3D"row" style=3D"border-spacing: 0; border-collapse: co=
llapse; vertical-align: top; text-align: left; width: 100%; position: relat=
ive; display: block; padding: 0px;">=0A                        <tr style=3D=
"vertical-align: top; text-align: left; padding: 0;" align=3D"left">=0A=0A =
                           <td class=3D"wrapper" style=3D"word-break: break=
-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-col=
lapse: collapse !important; vertical-align: top; text-align: left; position=
: relative; padding: 10px;" align=3D"left" valign=3D"top">=0A=0A           =
                     <table class=3D"twelve columns" style=3D"border-spacin=
g: 0; border-collapse: collapse; vertical-align: top; text-align: left; wid=
th: 580px; margin: 0 auto; padding: 0;">=0A                                =
    <tr style=3D"vertical-align: top; text-align: left; padding: 0;" align=
=3D"left">=0A                                        <td class=3D"twelve su=
b-columns" align=3D"center" style=3D"word-break: break-word; -webkit-hyphen=
s: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !impo=
rtant; vertical-align: top; text-align: left; min-width: 0px; width: 100% !=
important; padding: 0px 10px 10px 0px;" valign=3D"top">=0A                 =
                           <div style=3D"text-align: center;" align=3D"cent=
er">=0A                                                <img src=3D"http://=
REMOVED FOR PRIVACY/mysite/images/email/logo.png" style=3D"float: none=
; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; wi=
dth: auto; max-width: 100%; clear: both; display: block; margin: 0 auto;" a=
lign=3D"none" />=0A                                            </div>=0A   =
                                     </td>=0A                              =
      </tr>=0A                                </table>=0A=0A               =
                 <hr style=3D"color: #d9d9d9; height: 1px; background: #d9d=
9d9; border: none;" />=0A=0A                                <table class=3D=
"twelve columns" style=3D"border-spacing: 0; border-collapse: collapse; ver=
tical-align: top; text-align: left; width: 580px; margin: 0 auto; padding: =
0;">=0A                                    <tr style=3D"vertical-align: top=
; text-align: left; padding: 0;" align=3D"left">=0A                        =
                <td style=3D"word-break: break-word; -webkit-hyphens: auto;=
 -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; v=
ertical-align: top; text-align: left; padding: 0px 0px 10px;" align=3D"left=
" valign=3D"top">=0A                                            <!-- EMAIL =
CONTENT HERE -->=0A                                        </td>=0A        =
                                <td class=3D"expander" style=3D"word-break:=
 break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; bord=
er-collapse: collapse !important; vertical-align: top; text-align: left; vi=
sibility: hidden; width: 0px; padding: 0;" align=3D"left" valign=3D"top">=
=0A                                            =0A                         =
               </td>=0A                                    </tr>=0A        =
                        </table>=0A                            </td>=0A=0A =
                       </tr>=0A                    </table>=0A=0A          =
          <table class=3D"row" style=3D"border-spacing: 0; border-collapse:=
 collapse; vertical-align: top; text-align: left; width: 100%; position: re=
lative; display: block; padding: 0px;">=0A                        <tr style=
=3D"vertical-align: top; text-align: left; padding: 0;" align=3D"left">=0A =
                           <td class=3D"wrapper last" style=3D"word-break: =
break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; borde=
r-collapse: collapse !important; vertical-align: top; text-align: left; pos=
ition: relative; padding: 10px 0px 10px 10px;" align=3D"left" valign=3D"top=
">=0A=0A                                <table class=3D"twelve columns" sty=
le=3D"border-spacing: 0; border-collapse: collapse; vertical-align: top; te=
xt-align: left; width: 580px; margin: 0 auto; padding: 0;">=0A             =
                       <tr style=3D"vertical-align: top; text-align: left; =
padding: 0;" align=3D"left">=0A                                        <td =
align=3D"center" style=3D"word-break: break-word; -webkit-hyphens: auto; -m=
oz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vert=
ical-align: top; text-align: left; padding: 0px 0px 10px;" valign=3D"top">=
=0A                                            <center style=3D"width: 100%=
; min-width: 580px;">=0A                                                <p>=
TESTING BASE EMAIL TEMPLATE</p>=0A                                         =
   </center>=0A                                        </td>=0A            =
                            <td class=3D"expander" style=3D"word-break: bre=
ak-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-c=
ollapse: collapse !important; vertical-align: top; text-align: left; visibi=
lity: hidden; width: 0px; padding: 0;" align=3D"left" valign=3D"top">=0A   =
                                         =0A                               =
         </td>=0A                                    </tr>=0A              =
                  </table>=0A                            </td>=0A          =
              </tr>=0A                    </table>=0A                    <!=
-- container end below -->=0A                </td>=0A            </tr>=0A  =
      </table>=0A    </body>=0A</html>=0A
------=_NextPart_176699263819--

Here is the code I'm using to send the email:


$email = new Email();
$email->setTo($to); 
$email->setFrom($data['Email']); 
$email->setSubject($subject);

//set template
$email->setTemplate('Base');
// Send Email
$email->send();

I've contacted my hosting provider regarding the email and they said that it's not a problem from their end.
And seeing as the email sends via the PHP mail() function fine, I'm assuming it's not a problem from their end.

Can anyone suggest what I can try to bug fix this problem?

Avatar
guci0

Community Member, 2 Posts

5 April 2017 at 1:34am

Hello,

In /framework/email find Mailer.php and change:

[-] private static $default_message_encoding = 'quoted-printable';
[+] private static $default_message_encoding = 'base64';

save and do ?flush

Works like charm ;)

Avatar
brian_c

Community Member, 4 Posts

22 September 2017 at 11:36am

Better way (without hacking core) is to put this in your config.yml:

Mailer:
  default_message_encoding: 'base64'