Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:56:41+00:00 2026-06-11T10:56:41+00:00

I am currently working on attaching mails using swiftmailer. I need to attach a

  • 0

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.

This is what i tried

function sendMail($mailer,$subject , $to , $msg, $isAttachment, $attach)
    {
        $message = \Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom('abc@gmail.com')
        ->setTo('xyz@gmail.com')
        ->setBody($msg)
        ->setContentType("text/html");

    if($isAttachment){

            $message->attach(Swift_Attachment::fromPath($attach));
        }

        $this->get('mailer')->send($message);

    } 

$isAttachment is a Boolean variable which has 1 if there is a attachment.

This is the error I get.

Fatal error: Class 'MyProject\FrontBundle\Controller\Swift_Attachment' not found in /var/www/ABC/src/Myproject/FrontBundle/Controller/trialController.php on line 187

This is the first time i am working in swiftmailer .. So pardon me if this question sounds naive.

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:56:42+00:00Added an answer on June 11, 2026 at 10:56 am

    Namespacing problem. You did \Swift_Message::newInstance so you have to do:

    $message->attach(\Swift_Attachment::fromPath($attach));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently composing an HTML-Mail using MFMailComposer. Everything like Background Color etc. is working
currently I am working on an image slider with jquery. I have downloaded the
Currently working on a bespoke ecommerce application using Codeigniter. I have a products table
Currently working on a game, and is converting it to retina. I am using
Im currently working on a project that requires the following. I need to be
Currently working with Oracle, but will also need a solution for MS SQL. I
I'm working on a validation project and I currently have it set up where
Currently working on an ASP.NET MVC 3.0 application and using FormsAuthentication . When the
Currently working on a Swing application and I need to use a ListSelectionListener to
Currently working on rails 3. I made changes in my css file to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.