3

I want to send confirmation email to users. I did install swiftmailer with composer and these are my configuration in parameters. yml and config.yml

parameters:
database_host: 127.0.0.1
database_port: null
database_name: xxxx
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: xxxxx@xxxxxx.com
mailer_password: xxxx
secret: ea293ee3152cb8522e591a6cb821f950cc67f499
spool:
        type:                 file

mailer_port: 587
mailer_encryption: tls
mailer_logging: '%kernel.debug%'

config.yml

swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }

I added this code to my controller and I tested but nothing sent:

    $message = \Swift_Message::newInstance()
                ->setSubject('hello')
                ->setFrom('example@gmail.com')
                ->setTo('xx.xx@xxx.tn')
                ->setBody('@servicom/pages/profile_commercial.html.twig', 'text/html');

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

I want to ask if the problem is from the configuration or from the code.

Thanks in advance.

Malek Zarkouna
  • 943
  • 10
  • 21

2 Answers2

1

See if you need some other parameters like encryption (typicaly tls) or port (generaly 587).

Documentation for adding properties there

Kall Drogo
  • 56
  • 7
  • i add this parameters in parameters.yml or in config.yml or config_dev.yml ? – Malek Zarkouna Aug 11 '17 at 14:48
  • 1
    in parameters.yml, you set the variables (variable_name: value) and in config.yml you link your variables (parameter: "%variable_name%"), to one of these parameters. – Kall Drogo Aug 11 '17 at 14:51
  • i changed parameters but still nothing sent – Malek Zarkouna Aug 11 '17 at 15:02
  • 1
    That was the way I resolve the same problem. Are you sure of your OVH configuration ? Otherwise, I don't know, sorry... – Kall Drogo Aug 11 '17 at 15:09
  • i changed to gmail but nothing sent !! can u drop your configuration for gmail ? – Malek Zarkouna Aug 11 '17 at 15:11
  • 1
    I follow the OVH instructions : https://docs.ovh.com/fr/fr/web/emails/mail-mutualise-guide-configuration-dun-e-mail-mutualise-ovh-sur-linterface-de-gmail/, I'm looking for an english version, I'll come back when I get it – Kall Drogo Aug 11 '17 at 15:15
  • Well done ! So it was not only aditional parameters as I thought. For the smtp_port, I had it on my parameters.yml if I remember well, it's not necesseraly in your send method. But if it works, it's not important... Good job. – Kall Drogo Aug 15 '17 at 21:33
1

Finally i fixed the issue by debugging first then adding the ini_set() so i share this solution : Parameters.yml :

parameters:
    database_host: 127.0.0.1
    database_port: null
    database_name: xxxxx
    database_user: root
    database_password: root
    mailer_transport: smtp
    mailer_host: ssl0.ovh.net
    mailer_user: xxxx@myhost.com
    mailer_password: toguess
    encryption: ssl
    auth_mode: login
    secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Add this to the function send :

 ini_set('SMTP','ssl0.ovh.net');
 ini_set('smtp_port',587);

And this for the Debug :

if ( $this->get('mailer')->send($message)) {
                echo '[SWIFTMAILER] sent email to ' . 'malek.zarkouna@esprit.tn';
                echo '' . $mailLogger->dump();
            } else {
                echo '[SWIFTMAILER] not sending email: ' . $mailLogger->dump();
            }
Malek Zarkouna
  • 943
  • 10
  • 21