I got a strange behavior when sending email using Swiftmailer
here is the paramaters:
#Swiftmailer parameters @ app/config/parameters.yml
parameters:
mailer_transport: smtp
mailer_host: ssl0.ovh.net
mailer_user: my_account@my_domain.com
mailer_password: my_account_password
mailer_port: 465
auth_mode: plain
encryption: ssl
the config
# Swiftmailer Configuration @ app/config/config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
port: "%mailer_port%"
encryption: "%encryption%"
auth_mode: "%auth_mode%"
Now the controller and the action
class MailTestController extends Controller
{
public function SymfonyParamatersAction()
{
$message=\Swift_Message::newInstance()
->setSubject('smtp test with sm params')
->setFrom('my_account@my_domain.com')
->setTo('my_account@gmail.com')
->setBody('this is a test')
;
$result =$this->get('mailer')->send($message);
dump($this->get('mailer')->getTransport());die;
//return $this->render('...');;
}
}
So in the profiler I got one email sent but I dont receive any mail
I added this action to my controller
public function DirectParamatersAction()
{
$transport = \Swift_SmtpTransport::newInstance('ssl0.ovh.net', 465,'ssl')
->setUsername('my_account@my_domain.com')
->setPassword('my_account_password')
;
$transport->start();
$mailer = \Swift_Mailer::newInstance($transport);
$message=\Swift_Message::newInstance()
->setSubject('smtp test with direct params')
->setFrom('my_account@my_domain.com')
->setTo('my_account@gmail.com')
->setBody('this is a test')
;
$result =$mailer->send($message);
dump($transport);die;
return $this->render('.........');
}
with this action I received the message
the funny part (strange behavior) is when running these actions, I get different result:
1=> message is sent
2=> Expected response code 250 but got code "235", with message "235 ok, go ahead (#2.0.0)
3=>Connection could not be established with host ssl0.ovh.net [Connection timed out #110]
I clean the cache every time I change the config
I have to reload the page again and again to send the message
my question is what is wrong with the parameters and the first action?
secondly how to avoid this strange behavior?