Reputation: 11
I am trying to send mail via mandrill app using swift mailer. This is my code:
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com',587);
$transport->setUsername($username);
$transport->setPassword($password);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('New Order '.$reservationNumber)
// Set the From address with an associative array
->setFrom(array('[email protected]' => 'domain.com'))
// Set the To addresses with an associative array
->setTo('[email protected]')
// Give it a body
->setBody($body,'text/html');
$mailer->send($message);
Credentials are 100% good. And i get timeout error: Connection could not be established with host smtp.mandrillapp.com [Connection timed out #110].
It looks like something is blocking connection. Maybe this is issue with server configurations? We are using WHM software on our centos server
Upvotes: 1
Views: 7267
Reputation: 1561
Here it actually worked when I increased the timeout:
$transport = Swift_SmtpTransport::newInstance('mail_server', 'mail_port', 'tls')
->setUsername('mail_user')
->setPassword('mail_pass')
->setTimeout(120)
;
The server I tried to access works with IPv6, maybe there is an issue with related to that.
Upvotes: 1
Reputation: 59
I've just been doing battle with exactly the same problem, but with smtp.gmail.com. It just would not work, even though the username/password etc were all correct.
In my case it seems that when PHP tries to connect to smtp.gmail.com, it gets the IPv6 address back - but their server seems to not be listening on that, since the Swiftmailer responds with the same timeout error you get.
But when I swapped in its IPv4 address (got by ping-ing it), it connected and sent the email just fine.
So find out what smtp.mandrillapp.com's IPv4 address is and try that IP in place of the hostname in the code. Does that connect and send now? It did for me.
It's not ideal coding in an IP address - given that they could change it at any minute - but at least you will get some emails sent
Upvotes: 2