title: Conditional attachment of file using swiftmailer and symfony2
body: <p>I am currently working on attaching mails using swiftmailer. I need to attach a image file to the mail sometimes and sometimes I have to send the mail without the attachment.</p>
  
  <p>This is what i tried</p>
  
  <pre><code>function sendMail($mailer,$subject , $to , $msg, $isAttachment, $attach)
      {
          $message = \Swift_Message::newInstance()
          -&gt;setSubject($subject)
          -&gt;setFrom('abc@gmail.com')
          -&gt;setTo('xyz@gmail.com')
          -&gt;setBody($msg)
          -&gt;setContentType("text/html");
  
      if($isAttachment){
  
              $message-&gt;attach(Swift_Attachment::fromPath($attach));
          }
  
          $this-&gt;get('mailer')-&gt;send($message);
  
      } 
  </code></pre>
  
  <p><code>$isAttachment</code> is a Boolean variable which has <code>1</code> if there is a attachment. </p>
  
  <p>This is the error I get.</p>
  
  <pre><code>Fatal error: Class 'MyProject\FrontBundle\Controller\Swift_Attachment' not found in /var/www/ABC/src/Myproject/FrontBundle/Controller/trialController.php on line 187
  </code></pre>
  
  <p>This is the first time i am working in swiftmailer .. So pardon me if this question sounds naive.</p>
  
  <p>Thanks in Advance.</p>