2

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. For example:

$email->send();

Here is a screen shot of the email that I'm receiving.

Screenshot

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 setting the character type as an email header in the controller $email->addCustomHeader(...)
  • I have tried sending an HTML email from the standard php mail() function, and HTML content is sending fine. Emails work as expected.
  • I contacted my hosting provider and asked them if they could look in to it. They said it's not a problem from their end. I would tend to believe them, as the PHP mail() function sends fine, but the Silverstripe function does not.
  • I have tried $email->sendPlain() and the email sends in plain text, but there is no issues with multipart messages.
  • I have tried sending an email with the default Silverstripe email template (GenericEmail.ss)
  • I am using Shea Dawson's "Blocks" module, to send the email from a Contact Block I have created.
  • I have other website builds using SS 3.1.18 that send email templates as expected. I am using SS 3.4.

Here's the code that I'm using to send the email:

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

// Send Email
$email->send();

Here's the raw source from the email:

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--

Can anyone help me debug this problem? Let me know if there's any other information you require. Thanks for your help in advance...

Dallby
  • 596
  • 4
  • 19
  • I have experienced same issue sending mail from a local vagrant testbed to my office 365 account. But if the SS was on a remote server that has the mail settings set up correctly it came all right so I deemed it as a configuration issue on the sending server, not silverstripe so I didn't dive on the issue too deeply sadly. I just ended up using mailhog on the vagrant box to test the email there without actually sending them further. – Olli Tyynelä Nov 29 '16 at 10:33
  • @FinBoWa thanks for the reply. I have it set up on a remote server, not a local server. We have other sites using SS 3.1.18 that send emails as expected. – Dallby Nov 29 '16 at 21:49
  • Are the ss 3.1 sites on the same server, who has set the email sending settings on that server that has the issues? I have only experienced it on a box that most likely had some issues on the email forwarding settings, but not on any of our CPANEL sites yet. – Olli Tyynelä Nov 30 '16 at 06:41
  • But I think it might be worth it to add a issue to ss framework repository as this could be an bug that is lurking somewhere in the core also. – Olli Tyynelä Nov 30 '16 at 06:48
  • @FinBoWa thanks for your responses. Much appreciated. The email settings for the server are set by the hosting provider. We haven't changed anything between the domains. I guess it's whatever was set by default by the provider? Essentially we build locally in SS, package everything up in a zip, and extract it on the server. I'll look in to adding this issue to the repo. – Dallby Nov 30 '16 at 22:38
  • @FinBoWa just remembered I posted this previously on the SS repo, and they said they didn't feel it was a SS issue. Told me to post it on the forums. Did that, got no response. I guess I'll try the IRC channel. :/ – Dallby Nov 30 '16 at 23:14
  • @Dalby id would have like to see more details on the remote env. Is the ss runnin on a shared hosting or is it a real server instance that you have root access? – Olli Tyynelä Dec 01 '16 at 08:43
  • But as a "quick" fix: could you configure the server to use some other smtp service for the timebeing, or have a quick test with the https://packagist.org/packages/tony13tv/silverstripe-sendgrid ? That way would have some more data to reopen the issue either on SS repos or with your hosting company. – Olli Tyynelä Dec 01 '16 at 08:46
  • @FinBoWa I guess it's a shared hosting service. We have our hosting provider. We don't have root access unfortunately, or direct access to logs. I have to contact the support team if I want to see them :/ Thanks for the tip with send grid. I'll give that a crack and see if the problem persists. – Dallby Dec 01 '16 at 22:30
  • See also: http://stackoverflow.com/questions/5458439/php-sent-emails-have-0a-0a-instead-of-new-lines – wmk Feb 10 '17 at 07:54

0 Answers0