1
votes

I am trying to send an email using SwiftMailer bundle on Symfony. I am able to send a mail through the command :

swiftmailer:email:send    
From: myemail
To: emailRecipient
Subject: Hi
Body: This is a test
Sent 1 emails
Done.

After submitting my form, I would like to send my email. I can see them on my production server :

/home/sga/www/app/spool/default

So I tried to send them using :

swiftmailer:spool:send --env=prod

Finally I get :

Processing default mailer... 0 emails sent
Done.

swiftmailer:debug"
[swiftmailer] Current mailers
Name                     Transport Spool Delivery Single Address
default (default mailer) smtp      YES   YES   

My config.yml file :

# Swiftmailer Configuration
swiftmailer:
    transport: smtp
    host:      myhost
    username:  ~
    password:  ~
    spool:
        type: file
        path: "%kernel.root_dir%/spool"

I don't know why no emails are sent...

2
Are your mails being saved into %kernel.root_dir%/spool? Maaybe this is a file permissions issue, your application just cannot write into this file?Vera
Yes they are. I checked the permission file : spool/default has got 0755 but for my emails I've got 644. I tried to change the permission but it says I cannot due to "Permission denied". The owner is www-data.. Do you know how can I change file permission ?scamp

2 Answers

1
votes

Finally I just changed the transport :

swiftmailer:
transport: sendmail
host:      /usr/bin/sendmail
username:  ~
password:  ~
spool:     { type: memory }

My email is send without using the Symfony command but I've still got my problem of sending an email to gmail address failure.

0
votes

it turns out that my gmail recipient address caused that. Maybe gmail classified my email address as a spam or refused to send my message. But I've got nothing on my gmail spam folder...

EDIT :

it refuses to send an email for all address which doesn't have the same host. For instance : it sends only emails with @example.com So :

->setFrom('[email protected]')
->setTo('[email protected]')
doesn't work 

But :

->setFrom('[email protected]')
->setTo('[email protected]')
is working

As a remainder :

$transport = \Swift_SmtpTransport::newInstance("smtp.example.com", 25);
    $transport->setUsername("xxx");
    $transport->setPassword("YYYY");

    $mailer = \Swift_Mailer::newInstance($transport);

    $message = \Swift_Message::newInstance()
            ->setSubject($subject)
            ->setContentType("text/plain; charset=UTF-8")
            ->setFrom('[email protected]')
            ->setTo('[email protected]')
            ->setBody($body, 'multipart/alternative')
            ->addPart($body, 'text/html')
            ->addPart($bodyPlain, 'text/plain');
    if (!$mailer->send($message, $failures)) {
        echo "Failures:";
        print_r($failures);
    }

What i've got as a failure :

Failures:Array ( [0] => [email protected] )