Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Sending an email with attachment, with swiftmailer
  • Hi mates,

    I am new to this swiftmailer package. I have installed it perfectly in my fuelphp.

    i have this code

    $transport = \Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465,'ssl')
                            ->setUsername('xxx@gmail.com')
                            ->setPassword('xxxx');

                //Create the Mailer using your created Transport
                $mailer = \Swift_Mailer::newInstance($transport);
                
                
                //Create a message
                $message = \Swift_Message::newInstance('Wonderful Subject')
                  ->setFrom(array('khomeini8122@gmail.com' => 'komeng'))
                  ->setTo(array('khomeini@microad.co.id'))
                  ->setBody('Here is the message itself');
                $message->attach(Swift_Attachment::fromPath('guitar-600x600.jpg')->setDisposition('inline'));
                
                //Send the message
                $result = $mailer->send($message);
                
                return $result;


    well basically i'm trying to send an email with a .jpg attachment. if i comment the attach(), the code works perfectly and i got the email, is there something wrong with the way i use attach() function?
  • HarroHarro
    Accepted Answer
    Why not use Fuel's own email package? That doesn't have this problem.

    For problems with SwiftMailer you will probably have more luck on their forum?

    But my wild guess would be: you're not passing a FQFN to fromPath() but a relative filename. So what you do think the current working path for that method is? And is that file there?
  • at first i passed parameters with fuel email package

    mail(something, something, something) but it works when i don't have the need to attach file. Yes, the file is there in the same folder with the controller.
  • Fuel's own email package has full support for both attachments and inline images (if you use a HTML message).

    You seem to connect to Google for mail, then you should not use the transport type "mail", but use SMTP. See http://docs.fuelphp.com/packages/email/troubleshooting.html#/googlemail on how to configure the Email package for Google.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion