<p>I think I found my solution. To recap, I have a front-end form where a user that is not the author is permitted to make changes to an existing entry. I was creating a new Entry model instead of retrieving the Entry that I wanted to update. The answer getEntryById(). </p>

<pre><code>$this-&gt;requirePostRequest();

$entryId = craft()-&gt;request-&gt;getRequiredPost('entryId'); 
//entryId passed to controller from front-end form
$entry = craft()-&gt;entries-&gt;getEntryById($entryId, $localeId = null);
</code></pre>

<p>Then reset values that I am changing. </p>

<pre><code>if ( $editorialScore &gt;= 3) {
$entry-&gt;enabled = true;
} else {
$entry-&gt;enabled = false;
    }   
    $entry-&gt;getContent()-&gt;editorialScore = $editorialScore;
    $entry-&gt;getContent()-&gt;editorialNotes  = $editorialNotes;
</code></pre>

<p>Follow that with </p>

<pre><code>$success = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>I am then able to get Author's email address using Brad's suggested </p>

<pre><code>$email = $entry-&gt;getAuthor()-&gt;email;
</code></pre>

CC BY-SA 3.0
2014-09-23T04:31:27.537Z
2014-09-23T04:31:27.537Z
David A McInnis
<p>I assume you're talking about getting the email address of the currently logged in user?  That's what <a href="http://buildwithcraft.com/classreference/models/EntryModel" rel="nofollow">EntryModel's</a> authorId property will get set to, if one isn't explicitly supplied.</p>

<p>If so, you can do that with:</p>

<pre><code>$email = craft()-&gt;userSession-&gt;getUser()-&gt;email;
</code></pre>

<p>If you want to get the email address of the user that is the author of the entry, then you can do:</p>

<pre><code>$email = $entry-&gt;getAuthor()-&gt;email;
</code></pre>

CC BY-SA 3.0
2014-09-22T22:20:34.500Z
No, I want to get the email address of the user that created the entry.
David A McInnis
CC BY-SA 3.0
2014-09-22T22:23:04.703Z
Updated the answer.
Brad Bell
CC BY-SA 3.0
2014-09-22T22:58:19.607Z
Given my code above. I keep getting a message. "Trying to get property of non-object" which leads me to believe that I do not have the current entry loaded. If true, how do I load the entry?
David A McInnis
CC BY-SA 3.0
2014-09-23T00:12:39.167Z
If you're getting that error with your code above, then you haven't explicitly set an author on the entry, yet.  If you call saveEntry, without doing that, then `craft()->userSession->getUser()` will be assigned as the author and you can access that user via $entry->getAuthor() *after* you've called saveEntry().
Brad Bell
CC BY-SA 3.0
2014-09-22T20:18:13.440Z
2014-09-22T22:22:51.147Z
2014-09-22T22:22:51.147Z
Brad Bell
<p>I have created a front-end form to facilitate editorial review of user submitted content. I have created a controller action to receive the post. </p>

<p>My question, how do I locate the email address of the author tied to this entry? My objective is to be able to email the author with the results of the editorial review. In order to accomplish this I need to know the user (author) email address etc. Here is my code.</p>

<pre><code>$this-&gt;requirePostRequest();

$entryId = craft()-&gt;request-&gt;getRequiredPost('entryId');
$editorialNotesInternal = craft()-&gt;request-&gt;getPost('fields.editorialNotesInternal');
$editorialScore = craft()-&gt;request-&gt;getPost('fields.editorialScore');
$editorialNotes = craft()-&gt;request-&gt;getPost('fields.editorialNotes');
$sectionId = craft()-&gt;request-&gt;getPost('sectionId');

$entry = new EntryModel();

$entry-&gt;id = $entryId;
$entry-&gt;sectionId = $sectionId;

if ( $editorialScore &gt;= 3) {
    $entry-&gt;enabled = true;
} else {
    $entry-&gt;enabled = false;
}   

$entry-&gt;getContent()-&gt;editorialScore = $editorialScore;
$entry-&gt;getContent()-&gt;editorialNotes  = $editorialNotes;
$entry-&gt;getContent()-&gt;editorialNotesInternal  = $editorialNotesInternal;

$success = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<plugin-development><entries><author>
Retrieve Author Email based on Entry Id
# Retrieve Author Email based on Entry Id

(Asked by: username_0 on 2014-09-22)

I have created a front-end form to facilitate editorial review of user submitted content. I have created a controller action to receive the post. 
My question, how do I locate the email address of the author tied to this entry? My objective is to be able to email the author with the results of the editorial review. In order to accomplish this I need to know the user (author) email address etc. Here is my code.
$this->requirePostRequest();

$entryId = craft()->request->getRequiredPost('entryId');
$editorialNotesInternal = craft()->request->getPost('fields.editorialNotesInternal');
$editorialScore = craft()->request->getPost('fields.editorialScore');
$editorialNotes = craft()->request->getPost('fields.editorialNotes');
$sectionId = craft()->request->getPost('sectionId');

$entry = new EntryModel();

$entry->id = $entryId;
$entry->sectionId = $sectionId;

if ( $editorialScore >= 3) {
    $entry->enabled = true;
} else {
    $entry->enabled = false;
}   

$entry->getContent()->editorialScore = $editorialScore;
$entry->getContent()->editorialNotes  = $editorialNotes;
$entry->getContent()->editorialNotesInternal  = $editorialNotesInternal;

$success = craft()->entries->saveEntry($entry);

**Tags:** plugin-development, entries, author

---

## 2 answers

### Answer by username_0 on 2014-09-23. Score: 1 | Accepted answer

I think I found my solution. To recap, I have a front-end form where a user that is not the author is permitted to make changes to an existing entry. I was creating a new Entry model instead of retrieving the Entry that I wanted to update. The answer getEntryById(). 
$this->requirePostRequest();

$entryId = craft()->request->getRequiredPost('entryId'); 
//entryId passed to controller from front-end form
$entry = craft()->entries->getEntryById($entryId, $localeId = null);

Then reset values that I am changing. 
if ( $editorialScore >= 3) {
$entry->enabled = true;
} else {
$entry->enabled = false;
    }   
    $entry->getContent()->editorialScore = $editorialScore;
    $entry->getContent()->editorialNotes  = $editorialNotes;

Follow that with 
$success = craft()->entries->saveEntry($entry);

I am then able to get Author's email address using Brad's suggested 
$email = $entry->getAuthor()->email;


---

### Answer by username_1 on 2014-09-22. Score: 3

I assume you're talking about getting the email address of the currently logged in user?  That's what EntryModel's authorId property will get set to, if one isn't explicitly supplied.
If so, you can do that with:
$email = craft()->userSession->getUser()->email;

If you want to get the email address of the user that is the author of the entry, then you can do:
$email = $entry->getAuthor()->email;

> **Comments:**
> **username_0**: No, I want to get the email address of the user that created the entry.  
> **username_1**: Updated the answer.  
> **username_0**: Given my code above. I keep getting a message. "Trying to get property of non-object" which leads me to believe that I do not have the current entry loaded. If true, how do I load the entry?  
> **username_1**: If you're getting that error with your code above, then you haven't explicitly set an author on the entry, yet.  If you call saveEntry, without doing that, then `craft()->userSession->getUser()` will be assigned as the author and you can access that user via $entry->getAuthor() *after* you've called saveEntry().  

---

