Forums / General Questions / My zen_mail sends text-only emails

My zen_mail sends text-only emails

Views: 962

Results 1 to 8 of 8
19 Oct 2015, 2:31 PM
#1
allthingsidleroy avatar

allthingsidleroy

New Zenner

Join Date:
May 2013
Posts:
38
Plugin Contributions:
0

My zen_mail sends text-only emails

During checkout, we're trying to send an html email to an email address. It works, but just not html. I've tested sending a newsletter and I can receive html emails fine from my zen cart install. All my email options settings are set to enable html. The email transport method is PHP.

Here's the code I'm using. If you guys could point me in the right direction it would be much appreciated.

$subject = "Test Subject";
$body = "<p>The body of the email.</p>";
zen_mail("", $email, $subject, $body, STORE_NAME, STORE_ADMIN_EMAIL, array("EMAIL_MESSAGE_HTML" => $body));
19 Oct 2015, 3:51 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: My zen_mail sends text-only emails

allthingsidLeroy:

During checkout, we're trying to send an html email to an email address. It works, but just not html. I've tested sending a newsletter and I can receive html emails fine from my zen cart install. All my email options settings are set to enable html. The email transport method is PHP.

Here's the code I'm using. If you guys could point me in the right direction it would be much appreciated.

$subject = "Test Subject";
$body = "<p>The body of the email.</p>";
zen_mail("", $email, $subject, $body, STORE_NAME, STORE_ADMIN_EMAIL, array("EMAIL_MESSAGE_HTML" => $body));

zen_mail can send html messages... Take a look at includes/functions/functions_email.php specifically at the zen_mail function and will see the following "guidance":

/**

  • Send email. This is the central mail function.
  • If using "PHP" transport method, the SMTP Server or other mail application should be configured correctly in server's php.ini
  • @param string $to_name The name of the recipient, e.g. "Jim Johanssen"
  • @param string $to_email_address The email address of the recipient, e.g. [email protected]
  • @param string $email_subject The subject of the email
  • @param string $email_text The text of the email, may contain HTML entities
  • @param string $from_email_name The name of the sender, e.g. Shop Administration
  • @param string $from_email_address The email address of the sender, e.g. [email protected]
  • @param array $block Array containing values to be inserted into HTML-based email template
  • @param string $module The module name of the routine calling zen_mail. Used for HTML template selection and email archiving.
  • This is passed to the archive function denoting what module initiated the sending of the email
  • @param array $attachments_list Array of attachment names/mime-types to be included (this portion still in testing, and not fully reliable)
  • @param string $email_reply_to_name Name of the "reply-to" header (defaults to store name if not specified, except for contact-us and order-confirmation)
  • @param string $email_reply_to_address Email address for reply-to header (defaults to store email address if not specified, except for contact-us and order-confirmation)
    **/
    function zen_mail($to_name, $to_address, $email_subject, $email_text, $from_email_name, $from_email_address, $block=array(), $module='default', $attachments_list='', $email_reply_to_name = '', $email_reply_to_address = '' )

the $block array should have fields corresponding to the HTML version of the email being sent.  More detail about how to compose that can be found in includes/classes/order.php within the function send_order_email or by using that function to send the email if it is an order email being sent.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Oct 2015, 4:06 PM
#3
allthingsidleroy avatar

allthingsidleroy

New Zenner

Join Date:
May 2013
Posts:
38
Plugin Contributions:
0

Re: My zen_mail sends text-only emails

Are all variables in a template required in the $html array?

19 Oct 2015, 5:07 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: My zen_mail sends text-only emails

allthingsidLeroy:

Are all variables in a template required in the $html array?

Fields not populated in the "$html_msg" variable will not be substituted in the template being used resulting in nothing being listed/filled for some fields, while others are populated from the information provided up-front in the call to zen_mail such as the to, from, etc... All of this is primarily controlled by the functions in includes/functions/functions_email.php..

Based on the code provided, the default template is used (email/email_template_default.html) which has the following content and includes the "variables" (ie. $EMAIL_SUBJECT) to be populated:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=$CHARSET" />
<base href="$BASE_HREF" />
<style type="text/css">
body {background-color:#ffffff; color:#000000; font-family:Verdana, Arial, Helvetica, sans-serif; text-align:center;}
a:link {color:#0066cc;}
a:hover {background-color:#eeeecc; color:#0066cc;}
a:visited {color:#0066cc;}
.holder {background-color:#f9f9f9; border:1px solid #9a9a9a; font-size:9px; text-align:left; width:550px;}
.header {font-size:10px; padding:0px; width:550px;}
.content {font-size:10px; padding:5px; width:550px;}
.footer {border-top:1px solid #9a9a9a; font-size:9px; margin-top:10px; text-align:center; width:550px;}
.extra-info {background-color:#cccc99; border:1px solid #9a9a9a; font-size:10px; margin-top:10px; padding:5px; width:550px;}
.extra-info-bold {font-weight:bold;}
.disclaimer {background-color:#f9f9f9; border:1px solid #cccccc; font-size:10px; margin-top:10px; padding:5px; width:550px;}
.disclaimer1 {color:#666666; padding:5px;}
.disclaimer1 a:link {color:#666666;}
.disclaimer1 a:visited {color:#666666;}
.disclaimer2 {color:#666666; padding:5px;}
.copyright {border-bottom:0px solid #9a9a9a; padding:5px;}
</style>
</head>
<body>
<div class="holder">
<!-- Header Section -->
<div class="header">
<img src="email/header.jpg" alt="logo" />
</div>
 
<!-- Content Section -->
<div class="content">
<div>$EMAIL_SUBJECT</div>
<div>$EMAIL_MESSAGE_HTML</div>
</div>
 
<!-- Footer Section -->
<div class="footer">
<div class="copyright">$EMAIL_FOOTER_COPYRIGHT</div>
</div>
</div>
<div class="disclaimer">
<div class="disclaimer1">$EMAIL_DISCLAIMER</div>
<div class="disclaimer2">$EMAIL_SPAM_DISCLAIMER</div>
</div>
$EXTRA_INFO
</body>
</html>

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Oct 2015, 5:26 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: My zen_mail sends text-only emails

Is your $to_address ($email as provided in the call) in your customer database? If not, then this is one condition which would cause the email to be sent as text only... (But is not so affected for newsletters.)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Oct 2015, 5:29 PM
#6
allthingsidleroy avatar

allthingsidleroy

New Zenner

Join Date:
May 2013
Posts:
38
Plugin Contributions:
0

Re: My zen_mail sends text-only emails

mc12345678:

Is your $to_address ($email as provided in the call) in your customer database? If not, then this is one condition which would cause the email to be sent as text only... (But is not so affected for newsletters.)

Yeah, this ended up being the problem. The comments said that the HTML format would be assumed if one isn't specified (like in this case), but that never actually happens.

I edited line 154 in 'includes/functions/functions_email.php' to the following and everything works now.

$customers_email_format = ($result->RecordCount() > 0) ? $result->fields['customers_email_format'] : 'HTML';
19 Oct 2015, 5:52 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: My zen_mail sends text-only emails

allthingsidLeroy:

Yeah, this ended up being the problem. The comments said that the HTML format would be assumed if one isn't specified (like in this case), but that never actually happens.

I edited line 154 in 'includes/functions/functions_email.php' to the following and everything works now.

$customers_email_format = ($result->RecordCount() > 0) ? $result->fields['customers_email_format'] : 'HTML';


Well, kind of a weird way to go about the following, but looks like if you are sending emails to people that haven't established an account on your system (or they have removed their email address from the ZC store) then may want to include some text about if unable to see the message as html, would prefer it to be provided by text only, then to register with your store and set the default email message type to text.  (That is unless you have completely disabled that ability.) Though still somewhat wonder what direct (automated?) emails are being coordinated to go to people that haven't established an account... 

But glad that a solution was found.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Oct 2015, 7:09 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: My zen_mail sends text-only emails

What's the current value for Configuration->E-Mail Options->Enable HTML Emails?