Search code examples
phpsymfonyemailswiftmailerovh

Sending mail with swiftmailer via OVH mail


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: [email protected]
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('[email protected]')
                ->setTo('[email protected]')
                ->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.


Solution

  • 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: [email protected]
        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 ' . '[email protected]';
                    echo '' . $mailLogger->dump();
                } else {
                    echo '[SWIFTMAILER] not sending email: ' . $mailLogger->dump();
                }