<p><a href="https://github.com/Synchro/PHPMailer" rel="nofollow">PHPMailer</a> is only going work with local files for attachments, so you'll need to download the file from S3 into a known location, and pass that location in as the first parameter to <code>addAttachment</code>.</p>

CC BY-SA 3.0
2015-08-11T23:37:46.030Z
2015-08-12T02:55:08.150Z
2015-08-12T02:55:08.150Z
Brad Bell
<p>When my plugin runs, I'm getting a PHP Mailer Exception error stating:</p>

<p><em>"Could not access file: <a href="http://s3.amazonaws.com/patternmanager/clients/healthstream/question-attachments/download.jpeg" rel="nofollow">http://s3.amazonaws.com/patternmanager/clients/healthstream/question-attachments/download.jpeg</a>"</em></p>

<p>The url being pulled in is correct, and the file exists. I'm still very new to this, but the best I can figure out is that this is some kind of permissions issue?</p>

<p>Is there something in my code that might be causing a problem? Am I calling in the attachments correctly? Any direction is greatly appreciated.</p>

<pre><code>public function init()
{
    parent::init();

    //Event: onSaveEntry
    craft()-&gt;on('entries.saveEntry', function(Event $event)
    {

        $entry = $event-&gt;params['entry'];
        $isNewEntry = $event-&gt;params['isNewEntry'];
        $entrySection = $entry-&gt;section;

        $attachments = $entry-&gt;questionAttachments;

        if ($isNewEntry and $entrySection == 'Questions')  {
            //Get all users from UserGroup
            $user_criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
            $user_criteria-&gt;groupId = '9';
            $users = $user_criteria-&gt;find();

            //Send to each User
            foreach ($users as $user) {
                //Send Mail
                $email = new EmailModel();
                $email-&gt;toEmail = $user-&gt;email;
                $email-&gt;subject = 'New Question';
                $email-&gt;htmlBody    =

                'A new question has been posted: &lt;a href="'.$entry-&gt;url.'" title="'.$entry-&gt;title.'"&gt;'.$entry-&gt;title.'&lt;/a&gt;';

                if ($attachments) {
                    foreach ($attachments as $attachment) {
                        $email-&gt;addAttachment($attachment-&gt;url, $attachment-&gt;filename, 'base64', $attachment-&gt;kind);
                    }
                }

                craft()-&gt;email-&gt;sendEmail($email);
            }
        }
    });
}
</code></pre>

<plugin-development><emails>
Getting a phpmailerException error due to my attachments when my plugin runs
# Getting a phpmailerException error due to my attachments when my plugin runs

(Asked by: username_0 on 2015-08-11)

When my plugin runs, I'm getting a PHP Mailer Exception error stating:
"Could not access file: http://s3.amazonaws.com/patternmanager/clients/healthstream/question-attachments/download.jpeg"
The url being pulled in is correct, and the file exists. I'm still very new to this, but the best I can figure out is that this is some kind of permissions issue?
Is there something in my code that might be causing a problem? Am I calling in the attachments correctly? Any direction is greatly appreciated.
public function init()
{
    parent::init();

    //Event: onSaveEntry
    craft()->on('entries.saveEntry', function(Event $event)
    {

        $entry = $event->params['entry'];
        $isNewEntry = $event->params['isNewEntry'];
        $entrySection = $entry->section;

        $attachments = $entry->questionAttachments;

        if ($isNewEntry and $entrySection == 'Questions')  {
            //Get all users from UserGroup
            $user_criteria = craft()->elements->getCriteria(ElementType::User);
            $user_criteria->groupId = '9';
            $users = $user_criteria->find();

            //Send to each User
            foreach ($users as $user) {
                //Send Mail
                $email = new EmailModel();
                $email->toEmail = $user->email;
                $email->subject = 'New Question';
                $email->htmlBody    =

                'A new question has been posted: '.$entry->title.'';

                if ($attachments) {
                    foreach ($attachments as $attachment) {
                        $email->addAttachment($attachment->url, $attachment->filename, 'base64', $attachment->kind);
                    }
                }

                craft()->email->sendEmail($email);
            }
        }
    });
}

**Tags:** plugin-development, emails

---

## 1 answers

### Answer by username_1 on 2015-08-11. Score: 1

[PHPMailer](https://github.com/Synchro/PHPMailer) is only going work with local files for attachments, so you'll need to download the file from S3 into a known location, and pass that location in as the first parameter to `addAttachment`.


---

