title: Use PHPmailer to send attachment
body: <p>I'm using PHPmailer library to send emails and I need to send an attachment.</p>
  
  <p>Currently the file is stored on the server and I have the link to the file stored in var <code>$link</code>.</p>
  
  <p>I'm using the following to try and add the attachment but the email arrives with no attachment:</p>
  
  <pre><code>$phpmailer-&gt;AddAttachment('$link');
  </code></pre>
  
  <p>I have also tried it with a hardcoded path instead of my variable:</p>
  
  <pre><code>$phpmailer-&gt;AddAttachment('http://mysite.co.uk/link/to/my/file.pdf');
  </code></pre>
  
  <p>The email shows up but does not have any attachment. </p>
  
  <p>I have tried using <code>phpmailerException</code> to grab any errors but get no response. </p>
  
  <p>How else can I send an attachment with PHPmailer?</p>
  
  <p>Full PHP code:</p>
  
  <pre><code>require_once 'library/PHPMailer.php';
          $phpmailer = new PHPMailer();
          $phpmailer-&gt;isSMTP(); //switch to smtp
          $phpmailer-&gt;Host = 'smtp.sendgrid.net';
          $phpmailer-&gt;SMTPAuth = true;
          $phpmailer-&gt;SMTPSecure = 'ssl';
          $phpmailer-&gt;Port = 465;
          $phpmailer-&gt;Username = 'username';
          $phpmailer-&gt;Password = 'password';
          $phpmailer-&gt;AddAttachment('http://mysite.co.uk/blah/cv.pdf');
          //$phpmailer-&gt;AddAttachment('$link');
  
          $subject = 'Job Application';
  
          $messageConfirmation = "The &lt;b&gt; 'Apply for Job' &lt;/b&gt; form has recently been completed on &lt;b&gt;www.mysite.com.&lt;/b&gt;&lt;br/&gt;&lt;br/&gt; &lt;b&gt;Please see contact details below:&lt;br /&gt;&lt;br/&gt; &lt;/b&gt;";
          $messageConfirmation.= "&lt;b&gt;Applying for:&lt;/b&gt; $title &lt;br/&gt;&lt;br/&gt;";
          $messageConfirmation .= "&lt;b&gt;Name:&lt;/b&gt; $name &lt;br/&gt;&lt;br/&gt;&lt;b&gt;Surname:&lt;/b&gt; $surname &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Email:&lt;/b&gt; $email &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Comment:&lt;/b&gt; $comment &lt;br/&gt;&lt;br/&gt;";
          $messageConfirmation .= "&lt;b&gt;CV:&lt;/b&gt; $link&lt;br /&gt;&lt;br /&gt;";
          $messageConfirmation .= "Please can you call them back in the next 24 hours. &lt;br/&gt;&lt;br/&gt; Thank you \n\nMy Site&lt;br/&gt;&lt;br/&gt;";
  
  
          $imgheader = 'http://blah.co.uk/blah/wp-content/uploads/2014/11/header.png';
          $imgfooter = 'http://blah.co.uk/blah/wp-content/uploads/2014/11/footer.png';
  
          $message = '&lt;!DOCTYPE HTML&gt;'.
              '&lt;head&gt;'.
              '&lt;meta http-equiv="content-type" content="text/html"&gt;'.
              '&lt;title&gt;Email notification&lt;/title&gt;'.
              '&lt;/head&gt;'.
              '&lt;body&gt;'.
              '&lt;div id="header" style="width: 600px;height: auto;margin: 0 auto;color: #fff;text-align: center;font-family: Open Sans,Arial,sans-serif;"&gt;'.
              '&lt;img src="'.$imgheader.'" &gt;'.
              '&lt;/div&gt;'.
  
              '&lt;div id="outer" style="width: 600px;margin: 0 auto;margin-top: 10px;"&gt;'.
              '&lt;div id="inner" style="width: 600px;margin: 0 auto; padding-left: 20px;background-color: #fff;font-family: Open Sans,Arial,sans-serif;font-size: 13px;font-weight: normal;color: #444;margin-top: 10px;"&gt;'.
              '&lt;p&gt;'.$messageConfirmation .'&lt;/p&gt;'.
  
              '&lt;/div&gt;'.
              '&lt;/div&gt;'.
  
              '&lt;div id="footer" style="width: 600px;height: auto;margin: 0 auto;text-align: center;padding: 10px;font-family: Verdena;"&gt;'.
              '&lt;img src="'.$imgfooter.'" &gt;'.
              '&lt;/div&gt;'.
              '&lt;/body&gt;';
  
  
          $phpmailer-&gt;IsHTML(true);
          $phpmailer-&gt;AddAddress(CONTACTUSFORMEMAIL);
          $phpmailer-&gt;From = CONTACTUSFORMEMAIL;
          $phpmailer-&gt;FromName ='blah';
          $phpmailer-&gt;WordWrap   = 50; // set word wrap to 50 characters
          $phpmailer-&gt;Subject    = $subject;
          $phpmailer-&gt;Body       = $message;
          $phpmailer-&gt;Send();
  
  
  
          $data['success'] = true;
          $data['message'] = 'Thank you for your application';
  </code></pre>