I've registered with Amazon SES service with email limit setup and out of the sandbox. I've tried many PHPMailer function and all return me as error : Connexion time out (110). Is it possible the send mail from PHPMailer?
I have seen on Amazon SES site this link.
<?php
// Replace path_to_sdk_inclusion with the path to the SDK as described in
// http://docs.aws.amazon.com/aws-sdk-php/v2/guide/quick-start.html
define('REQUIRED_FILE','path_to_sdk_inclusion');
// Replace sender#example.com with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'sender#example.com');
// Replace recipient#example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'recipient#example.com');
// Replace us-west-2 with the AWS region you're using for Amazon SES.
define('REGION','us-west-2');
define('SUBJECT','Amazon SES test (AWS SDK for PHP)');
define('BODY','This email was sent with Amazon SES using the AWS SDK for PHP.');
require REQUIRED_FILE;
use Aws\Ses\SesClient;
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => REGION
));
$request = array();
$request['Source'] = SENDER;
$request['Destination']['ToAddresses'] = array(RECIPIENT);
$request['Message']['Subject']['Data'] = SUBJECT;
$request['Message']['Body']['Text']['Data'] = BODY;
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
echo("Email sent! Message ID: $messageId"."\n");
} catch (Exception $e) {
echo("The email was not sent. Error message: ");
echo($e->getMessage()."\n");
}
?>
I've copy all the codes, put my variable instead of showned in the demo script. Now I'm getting the error : You must use KEY ans SECRET_KEY to use this script... Where I cant put my KEY and SECRETKEY in the script? There is no explanation on how to do this.
Is there another way send email throught Amazon SES service?
Thanks!
So simple. I have to add key and secret in :
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => REGION,
'credentials' => array(
'key' => 'XXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXX',
)
));
and set XXXXXXXXXXXXXXXX full access to api in amazon security credentials
As far as I know PHP Mailer was not working with AWS SES by API, you should use SES SMTP with PHP Mailer.
The correct ports are 25, 465 or 587.
Related
I have created trial account on twilio and used test API credentials for sending the SMS, after sending the SMS it shows me SID in success but no message received by the phone number which i have added in 'TO' field.
You must use live credentials to send messages:
<?php
// this line loads the library
require('/path/to/twilio-php/Services/Twilio.php');
// you must use your live credentials!!!!
$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = '[AuthToken]';
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array(
'To' => "+15558675309",
'From' => "+15017250604",
'Body' => "Hey, hope this works!",
'MediaUrl' => "http://farm2.static.flickr.com/1075/1404618563_3ed9a44a3a.jpg",
));
It is explained here - https://www.twilio.com/docs/api/rest/test-credentials - test credentials do not connect to real phone numbers.
I'm trying to integrate and send emails with AWS SES service but for any reason I'm receiving an internal server error.
Here bellow I paste the code I'm using:
User controller
<?php
class User extends Controller
{
public function subscribe()
{
$ses = $this->model('modelSES');
}
}
?>
Extending class
<?php
class Controller
{
public function model($model, $connection = '')
{
require_once '../project/models/' . $model . '.php';
$db_err = 'http://' . HOST . '/error/database';
return new $model($connection, $db_err);
}
}
?>
Model modelSES
<?php
use Aws\Ses\SesClient;
class modelSES
{
protected $ses;
public function __construct()
{
require '../project/libs/vendor/autoload.php';
$this->ses = new SesClient([
'key' => 'XXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'region' => 'us-west-2',
'version' => '2010-12-01'
]);
}
}
?>
I also configured SES for the verified sender email:
I verified my email Address (it appears verified in the ses console).
I enabled DKIM.
I also have 3 CNAME recordsets registered on my Route 53.
I got an identity policy registered with the sender user associated
to the rights of ses:SendEmail and ses:SendRawEmail.
To install the AWS SDK, I followed the AWS-PHP-SDK Guide.
The PHP version i'm using is 5.5.6.
Sounds like the problem rounds when I create the object $this->ses = new SesClient but I don't find the way to connect it properly.
P.S Is HTTPS required?
What I'm doing to send mails through SES in php is simply use the SMTP Interface from AWS SES.
You'll need to obtain SMTP credentials as described here: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
And then you can just send via SMTP.
Trying to send email with Laravel using Mandrill. I've set up a test API on Mandrill and have put the API key into the services.php config array, and set the driver to 'mandrill'. Here's how I'm sending the email:
$data = array(
'activation_code' => $user->activation_code
);
Mail::send('emails.auth.activate', $data, function($message) use ($user)
{
$message->from('test#test.com', 'Test');
$message->to($user->email);
});
What could be causing the above error?
First Receiver Email Address.
$data = array(
'activation_code' => $user->activation_code,
'email' => 'abc#xyx.com'
);
Check your API Credential. Your API authentication may fail to send emails.
I have an online software that sends emails to Amazon SES. Currently I have a cron job that sends the emails via the SMTP with phpmailer to send the messages. Currently I have to max the send limit to around 300 every minute to make sure my server doesn't time out. We see growth and eventually I'd like to send out to 10,000 or more.
Is there a better way to send to Amazon SES, or is this what everyone else does, but with just more servers running the workload?
Thanks in advance!
You can try using the AWS SDK for PHP. You can send emails through the SES API, and the SDK allows you to send multiple emails in parallel. Here is a code sample (untested and only partially complete) to get you started.
<?php
require 'vendor/autoload.php';
use Aws\Ses\SesClient;
use Guzzle\Service\Exception\CommandTransferException;
$ses = SesClient::factory(/* ...credentials... */);
$emails = array();
// #TODO SOME SORT OF LOGIC THAT POPULATES THE ABOVE ARRAY
$emailBatch = new SplQueue();
$emailBatch->setIteratorMode(SplQueue::IT_MODE_DELETE);
while ($emails) {
// Generate SendEmail commands to batch
foreach ($emails as $email) {
$emailCommand = $ses->getCommand('SendEmail', array(
// GENERATE COMMAND PARAMS FROM THE $email DATA
));
$emailBatch->enqueue($emailCommand);
}
try {
// Send the batch
$successfulCommands = $ses->execute(iterator_to_array($emailBatch));
} catch (CommandTransferException $e) {
$successfulCommands = $e->getSuccessfulCommands();
// Requeue failed commands
foreach ($e->getFailedCommands() as $failedCommand) {
$emailBatch->enqueue($failedCommand);
}
}
foreach ($successfulCommands as $command) {
echo 'Sent message: ' . $command->getResult()->get('MessageId') . "\n";
}
}
// Also Licensed under version 2.0 of the Apache License.
You could also look into using the Guzzle BatchBuilder and friends to make it more robust.
There are a lot of things you will need to fine tune with this code, but you may be able to achieve higher throughput of emails.
If anyone is looking for this answer, its outdated and you can find the new documentation here: https://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/commands.html
use Aws\S3\S3Client;
use Aws\CommandPool;
// Create the client.
$client = new S3Client([
'region' => 'us-standard',
'version' => '2006-03-01'
]);
$bucket = 'example';
$commands = [
$client->getCommand('HeadObject', ['Bucket' => $bucket, 'Key' => 'a']),
$client->getCommand('HeadObject', ['Bucket' => $bucket, 'Key' => 'b']),
$client->getCommand('HeadObject', ['Bucket' => $bucket, 'Key' => 'c'])
];
$pool = new CommandPool($client, $commands);
// Initiate the pool transfers
$promise = $pool->promise();
// Force the pool to complete synchronously
$promise->wait();
Same thing can be done for SES commands
Thank you for your answer. It was a good starting point. #Jeremy Lindblom
My problem is now that i can't get the Error-Handling to work.
The catch()-Block works fine and inside of it
$successfulCommands
returns all the succeed Responses with Status-Codes, but only if an error occurs. For example "unverified address" in Sandbox-Mode. Like a catch() should work. :)
The $successfulCommands inside the try-Block only returns:
SplQueue Object
(
[flags:SplDoublyLinkedList:private] => 1
[dllist:SplDoublyLinkedList:private] => Array
(
)
)
I can't figure it out how to get the real Response from Amazon with Status-Codes etc.
Have read this and this and using example from here.
However, I am still having difficulty in sending emails as a verified Google user using OAuth. I have the valid OAuth tokens, secrets, and xoauth token as well.
My code to send the email:
$authenticateParams = array('XOAUTH', $initClientRequestEncoded);
$smtp = new Zend_Mail_Protocol_Smtp('smtp.gmail.com', 587, array(
"AUTH" => $authenticateParams, 'ssl' => 'tls'));
try {
// Create a new mail object
$mail = new Zend_Mail();
$mail->setFrom("aaaaa#gmail.com");
$mail->addTo("bbbbb#gmail.com");
$mail->setSubject("Your account has been created");
$email = "Thank you for registering!";
$mail->setBodyText($email);
$mail->send();
} catch (Exception $e) {
echo "error sending email . <BR>" . $e;
}
But this seems to send an anonymous email and not as the user authenticated. If I do:
$smtp = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array('AUTHENTICATE' => $authenticateParams, 'ssl' => 'tls'));
Zend_Mail::setDefaultTransport($smtp);
I get: exception 'Zend_Mail_Protocol_Exception' with message '5.5.1 Authentication Required.
I'm sure it's just a case of getting the mail transport smtp params right, but the documentation for sending SMTP emails is non-existent and I can't find any code examples for this.
Check out the following blog posts which will show you where you went wrong.
google smtp oauth2 authentication
send mail with gmail smtp and xoauth