<p>To setup/debug email issues in commerce it's easiest to set up the simplest possible email and work your way up from there.</p>

<ol>
<li><p>Check your Craft email settings - can you send &amp; receive the test email
successfully?</p></li>
<li><p>In Commerce settings, double check you have created your email correctly and that your template exists at the path you set.  To simplify
things initially, avoid using any variables in the subject and hardcode
an address to which the email will be sent</p></li>
<li><p>Check your order status and make sure you have assigned your email to it and that a '1' then appears in the 'Has Emails' column for that
status.  It's easiest to start with an email attached to the default
order status so you can be sure orders coming in will trigger the
email.</p></li>
<li><p>Create the simplest possible template for the email and just put in it something like <code>Huzzah, my email sent!</code> as an initial end
to end test that the email is being triggered when you submit an order</p></li>
</ol>

<p>At that point, your basic email should really send!  </p>

<p>If not, check your <code>commerce.log</code> file for errors.  If you have parsing errors in your email template, they will appear here, or you may get the somewhat obscure <code>[info] [plugin] [Forced] Can't send email if no status or emails exist.</code> which indicates something is wrong with the set up of the status &lt;> email relationship.</p>

<p>Most of the errors typically come from template errors in the actual email - trying to get data not available for example.  <code>commerce.log</code> will help with that, but another handy way of debugging your email templates is to put something like this at the top of them:</p>

<pre><code>{# for debugging! #}
{% if craft.request.getSegment(1)=="order-completed-debug" %}
     {% set order = craft.commerce.orders.id(craft.request.getSegment(2)).first() %}
     {# No order supplied or other issue?  Load latest order by default... #}
     {% if not order %}
         {% set order = craft.commerce.orders.first() %}
     {% endif %}
{% endif %}
</code></pre>

<p>Set up a <code>route</code> in Craft settings so that <code>/order-completed-debug/(number)</code> points at your email template and then you will be able to use your browser for much easier testing by going to <code>/order-completed-debug/&lt;someValidOrderID&gt;</code> in your browser rather than having to submit an order each time you change your email template!</p>

<p>Finally, I <strong>very strongly</strong> recommend you use a transactional email service like mailgun, sparkpost, postmark, mandrill etc. as if you use default phpemail you're very likely to run into email delivery issues.  The logging systems these (often free!) transactional email systems supply are worth their weight in gold as you can see if the email is even being sent or not very simply, which helps with issue diagnosis a LOT.</p>

<hr>

<p>For completeness, although this is a lot more advanced &amp; less general:</p>

<p>Another gotcha to note is that custom order fields are not necessarily set yet in the order completed email template as it seems this is actually sent out BEFORE the final order save occurs so if you're e.g. setting some data in a plugin method listening to <code>onBeforeOrderComplet=</code>, you'll need to work around this....so to reference those fields you have to use a special approach (currently?)</p>

<pre><code>{% set ISOrderNumber = order.content.ISOrderNumber ?? 'NONE' %}
</code></pre>

<p>Not the use of <code>.content</code> there - I need to use this to get at the field that is not yet saved in to the order as such.</p>

CC BY-SA 3.0
2017-05-04T07:50:13.443Z
That email debug route is so great. Thanks a lot for the tip.
sanderfish
CC BY-SA 3.0
2017-05-05T05:52:07.943Z
Yeah good huh?  I updated it above slightly to fall back on the latest order if you don't supply an id
Jeremy Daalder
CC BY-SA 3.0
2016-05-10T01:11:35.347Z
2017-05-04T08:27:57.340Z
2017-05-04T08:27:57.340Z
Jeremy Daalder
<p>I am having trouble with emails being sent by Commerce.  Checked my settings in Craft and sent test email.  Works.  Followed Commerce docs in setting up email.  Double checked, but still does not work.  My problem may be in my email file.  Not sure what to have here.  Anyone have an example of an email file I could look at to see what I need to do?</p>

CC BY-SA 3.0
2016-05-09T20:30:29.153Z
If you go to Craft > Settings > Email can you try sending a test email from the general email settings? Also, have you linked the email you have set up in Commerce settings to the default order status?
Luke Holder
CC BY-SA 3.0
2016-05-09T21:21:23.287Z
Hello Luke.  Yes I sent a test email from Craft and I received it.  Yes, I have linked the email to the default order status.
user1663102
CC BY-SA 3.0
2016-05-09T23:29:16.263Z
Have you checked your commerce.log file for parsing errors with the email template?
Jeremy Daalder
<plugin-craftcommerce>
Order Confirmation Email in Craft Commerce
# Order Confirmation Email in Craft Commerce

(Asked by: username_0 on 2016-05-09)

I am having trouble with emails being sent by Commerce. Checked my settings in Craft and sent test email. Works. Followed Commerce docs in setting up email. Double checked, but still does not work. My problem may be in my email file. Not sure what to have here. Anyone have an example of an email file I could look at to see what I need to do?

**Tags:** plugin-craftcommerce

> **Comments:**
> **username_1**: If you go to Craft > Settings > Email can you try sending a test email from the general email settings? Also, have you linked the email you have set up in Commerce settings to the default order status?  
> **username_0**: Hello Luke.  Yes I sent a test email from Craft and I received it.  Yes, I have linked the email to the default order status.  
> **username_2**: Have you checked your commerce.log file for parsing errors with the email template?  

---

## 1 answers

### Answer by username_2 on 2016-05-10. Score: 8 | Accepted answer

To setup/debug email issues in commerce it's easiest to set up the simplest possible email and work your way up from there.

Check your Craft email settings - can you send & receive the test email
successfully?
In Commerce settings, double check you have created your email correctly and that your template exists at the path you set.  To simplify
things initially, avoid using any variables in the subject and hardcode
an address to which the email will be sent
Check your order status and make sure you have assigned your email to it and that a '1' then appears in the 'Has Emails' column for that
status.  It's easiest to start with an email attached to the default
order status so you can be sure orders coming in will trigger the
email.
Create the simplest possible template for the email and just put in it something like Huzzah, my email sent! as an initial end
to end test that the email is being triggered when you submit an order

At that point, your basic email should really send!  
If not, check your commerce.log file for errors.  If you have parsing errors in your email template, they will appear here, or you may get the somewhat obscure [info] [plugin] [Forced] Can't send email if no status or emails exist. which indicates something is wrong with the set up of the status <> email relationship.
Most of the errors typically come from template errors in the actual email - trying to get data not available for example.  commerce.log will help with that, but another handy way of debugging your email templates is to put something like this at the top of them:
{# for debugging! #}
{% if craft.request.getSegment(1)=="order-completed-debug" %}
     {% set order = craft.commerce.orders.id(craft.request.getSegment(2)).first() %}
     {# No order supplied or other issue?  Load latest order by default... #}
     {% if not order %}
         {% set order = craft.commerce.orders.first() %}
     {% endif %}
{% endif %}

Set up a route in Craft settings so that /order-completed-debug/(number) points at your email template and then you will be able to use your browser for much easier testing by going to /order-completed-debug/ in your browser rather than having to submit an order each time you change your email template!
Finally, I very strongly recommend you use a transactional email service like mailgun, sparkpost, postmark, mandrill etc. as if you use default phpemail you're very likely to run into email delivery issues.  The logging systems these (often free!) transactional email systems supply are worth their weight in gold as you can see if the email is even being sent or not very simply, which helps with issue diagnosis a LOT.

For completeness, although this is a lot more advanced & less general:
Another gotcha to note is that custom order fields are not necessarily set yet in the order completed email template as it seems this is actually sent out BEFORE the final order save occurs so if you're e.g. setting some data in a plugin method listening to onBeforeOrderComplet=, you'll need to work around this....so to reference those fields you have to use a special approach (currently?)
{% set ISOrderNumber = order.content.ISOrderNumber ?? 'NONE' %}

Not the use of .content there - I need to use this to get at the field that is not yet saved in to the order as such.

> **Comments:**
> **username_3**: That email debug route is so great. Thanks a lot for the tip.  
> **username_2**: Yeah good huh?  I updated it above slightly to fall back on the latest order if you don't supply an id  

---

