I'm having a problem sending emails out through SMTP using Amazons SES. My code is relatively simple and looks like this:
require_once "Mail.php";
require_once 'Mail/mime.php';
$stmp_info= array (
'host' => 'ssl://email-smtp.us-east-1.amazonaws.com',
'port' => 465,
'auth' => true,
'username' => 'xxxxxx',
'password' => 'xxx'
);
$headers = array (
'From' => 'sender@example.com',
'To' => 'test@example.com',
'Subject' => 'Test Message'
);
$mime = new Mail_mime("
");
$mime->setTXTBody('Hello World');
$mime->setHTMLBody('<p>Hello World</p>');
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', $stmp_info);
$mail = $smtp->send('test@example.com', $headers, $body);
The problem is I always get this error:
Failed to connect to email-smtp.us-east-1.amazonaws.com:465 [SMTP: Invalid response code received from server (code: -1, response: )]
But this works for testing a connection:
[root@job-server-1 ~]# $ echo quit | nc -v email-smtp.us-east-1.amazonaws.com 25
-bash: $: command not found
Connection to email-smtp.us-east-1.amazonaws.com 25 port [tcp/smtp] succeeded!
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-376766033
Yet if I ping the address, it does not work. I've tried port 25, 465 and 587 for both tls and ssl. The weird part is it works on my local host and this error only occurs when I try to connect from my rackspace instance. Does anyoen have an idea of what can be causing this?
Verify your network setting with your instance. If you are using VPC , please do check your subnet and routing policies.
Its blocking to connect ses smtp from your instance.
Also fill Request to Remove Email Sending Limitations to remove some restrictions on port 25
hope it helps !!