Sending attachments within a plugin Using Craft 2. Here's my code, which sends the email fine if I remove the attachment part. Can anyone point me in the right direction?

$email = new EmailModel();
$email-&gt;toEmail = $toEmail;
$email-&gt;cc = $ccEmail;
$email-&gt;bcc = $bccEmail;
$email-&gt;subject = $subject;
$email-&gt;body = $body;
//$email-&gt;attachments = $attachments;

$attachments = [
  ['path'=&gt;'http://website.localhost/img/uploads/nameoffile.pdf',
  'name'=&gt;'afile',
  'encoding'=&gt;'base64',
  'type'=&gt;'application/pdf']
];
if (!empty($attachments)) {
  foreach ($attachments as $attachment) {
    if ($attachment) {
      $email-&gt;addAttachment($attachment['path'], $attachment['name'], 'base64', $attachment['type']);
    }
  }
}

if ($email-&gt;getErrors()) {
  throw new Exception('there are errors'); // exception not returned
} 

// SEND THE MAIL
if (craft()-&gt;email-&gt;sendEmail($email)) return true;
else throw new Exception('not sent'); // returns this exception
Craft 2 uses the PHPMailer library to send emails and the first thing its addAttachment() method does is take the first $path parameter that's passed in and run PHP's is_file() on it.

is_file() won't work on URLs like you're passing in, it expects the file to be on the local file system, so you'll need to download it locally and pass in that path.

It won't show up on the model as an error using $email-&gt;getErrors() because the library catches the exception, does some internal logging and returns false.  Craft doesn't have a change to add that particular error back on its EmailModel.