<p>Just because <a href="http://buildwithcraft.com/classreference/services/EmailService#sendEmailByKey-detail" rel="nofollow">EmailService::sendEmailByKey()</a> requires you to pass in a <a href="http://buildwithcraft.com/classreference/models/UserModel" rel="nofollow">UserModel</a>, doesn’t mean that the model has to represent an actual saved user. You can create one on the spot for them:</p>

<pre class="lang-php prettyprint-override"><code>$user = new UserModel();
$user-&gt;email = 'sergster@abc.xyz';
$user-&gt;firstName = 'John'; // optional
$user-&gt;lastName = 'Doe'; // optional

craft()-&gt;email-&gt;sendEmailByKey($user, 'my_key', $variables);
</code></pre>

CC BY-SA 3.0
2015-10-02T14:03:16.807Z
Oh yeah, that totally makes sense, thanks! Do you have any insight on the secnd part of my question, namely which version of the email message (control panel vs. translation file) takes precedence?
John O
CC BY-SA 3.0
2015-10-02T15:04:29.040Z
@JohnO I just edited your question to remove that second part; can you please post it as a new question? (You can see what you originally typed here: http://craftcms.stackexchange.com/posts/11701/revisions)
Brandon Kelly
CC BY-SA 3.0
2015-10-02T15:51:23.393Z
Thanks for taking care of editing it out. I re-posted the question here: http://craftcms.stackexchange.com/questions/11728/do-email-messages-use-control-panel-or-translation-file-template-when-sending-by
John O
CC BY-SA 3.0
2015-10-01T22:38:45.483Z
2015-10-01T22:38:45.483Z
Brandon Kelly
<p>In a custom plugin, I would like to use Craft's ability to register email message keys in order to keep emails consistent, and I would like to be able to send these emails to users as well as non-users. My understanding is that I would need to use the sendEmailByKey method of the EmailService to send emails using registered keys, which is defined like this:</p>

<pre><code>public function sendEmailByKey(UserModel $user, $key, $variables = array())
</code></pre>

<p>This method only accepts a UserModel for the recipient, so it doesn't look like there's a way to send an email by key to an arbitrary email address. Is there a different way to send these registered emails to non-users?</p>

CC BY-SA 3.0
2015-10-01T22:23:34.573Z
Could you just spin of a `new UserModel()` and assign your non-user email to it before calling `sendEmailByKey`?
Brad Bell
CC BY-SA 3.0
2015-10-02T14:04:12.770Z
Thanks, @BradBell! That seems like it should work and is the same solution Brandon Kelly suggested.
John O
<emails><usermodel>
Sending email by key to non-user
# Sending email by key to non-user

(Asked by: username_0 on 2015-10-01)

In a custom plugin, I would like to use Craft's ability to register email message keys in order to keep emails consistent, and I would like to be able to send these emails to users as well as non-users. My understanding is that I would need to use the sendEmailByKey method of the EmailService to send emails using registered keys, which is defined like this:
public function sendEmailByKey(UserModel $user, $key, $variables = array())

This method only accepts a UserModel for the recipient, so it doesn't look like there's a way to send an email by key to an arbitrary email address. Is there a different way to send these registered emails to non-users?

**Tags:** emails, usermodel
> **Comments:**
> **username_1**: Could you just spin of a `new UserModel()` and assign your non-user email to it before calling `sendEmailByKey`?  
> **username_0**: Thanks, @BradBell! That seems like it should work and is the same solution Brandon Kelly suggested.  

---

## 1 answers

### Answer by username_2 on 2015-10-01. Score: 4 | Accepted answer

Just because EmailService::sendEmailByKey() requires you to pass in a UserModel, doesn’t mean that the model has to represent an actual saved user. You can create one on the spot for them:
$user = new UserModel();
$user->email = 'sergster@abc.xyz';
$user->firstName = 'John'; // optional
$user->lastName = 'Doe'; // optional

craft()->email->sendEmailByKey($user, 'my_key', $variables);

> **Comments:**
> **username_0**: Oh yeah, that totally makes sense, thanks! Do you have any insight on the secnd part of my question, namely which version of the email message (control panel vs. translation file) takes precedence?  
> **username_2**: @JohnO I just edited your question to remove that second part; can you please post it as a new question? (You can see what you originally typed here: http://craftcms.stackexchange.com/posts/11701/revisions)  
> **username_0**: Thanks for taking care of editing it out. I re-posted the question here: http://craftcms.stackexchange.com/questions/11728/do-email-messages-use-control-panel-or-translation-file-template-when-sending-by  

---

