Simple Email Service

Amazon Simple Email Service provides a simple way to send e-mails without having to maintain your own mail server.  This PHP class is a REST-based interface to that service.

A bit of example code will be a good demonstration of how simple this class is to use. Please read through these examples, and then feel free leave a comment if you have any questions or suggestions.

Update: Daniel Zahariev has forked the project and implemented the missing SendRawEmail functionality as well as Sig V4 support. You can download it at his github project page.

First, you’ll need to create a SimpleEmailService class object:

require_once('ses.php');
$ses = new SimpleEmailService('Access Key Here', 'Secret Key Here');

If this is your first time using Simple Email Service, you will need to request verification of at least one e-mail address, so you can send messages:

print_r($ses->verifyEmailAddress('user@example.com'));
-------
Array
(
  [RequestId] => 1b086469-291d-11e0-85af-df1284f62f28
)

Every request you make to SimpleEmailService will return a request id. This id may be useful if you need to contact AWS about any problems.  For brevity, I will omit the request id if it is the only value returned from a service call.

After you’ve requested verification, you’ll get an e-mail at that address with a link. Click the link to get your address approved.  Once you’ve done that, you can use it as the ‘From’ address in the e-mails you send through SES.  If you don’t have production access yet, you’ll also need to request verification for all addresses you want to send mail to.

If you want to see what addresses have been verified on your account, it’s easy:

print_r($ses->listVerifiedEmailAddresses());
-------
Array
(
  [RequestId] => 77128e89-291d-11e0-986f-43f07db0572a
  [Addresses] => Array
    (
      [0] => user@example.com
      [1] => recipient@example.com
    )
)

Removing an address from the verified address list is just as easy:

$ses->deleteVerifiedEmailAddress('user@example.com');

This call will return a request id if you need it.

The only thing left to do is send an e-mail, so let’s try it. First, you’ll need a SimpleEmailServiceMessage object.  Then, you’ll want to set various properties on the message.  For example:

$m = new SimpleEmailServiceMessage();
$m->addTo('recipient@example.com');
$m->setFrom('user@example.com');
$m->setSubject('Hello, world!');
$m->setMessageFromString('This is the message body.');

print_r($ses->sendEmail($m));
-------
Array
(
  [MessageId] => 0000012dc5e4b4c0-b2c566ad-dcd0-4d23-bea5-f40da774033c-000000
  [RequestId] => 4953a96e-29d4-11e0-8907-21df9ed6ffe3
)

And that’s all there is to it!

There are a few more things you can do with this class. You can make two informational queries, try these out:

print_r($ses->getSendQuota());
print_r($ses->getSendStatistics());

For brevity I will not show the output of those two API calls. This information will help you keep track of the health of your account. See the Simple Email Service documentation on GetSendQuota and GetSendStatistics for more information on these calls.

You can set multiple to/cc/bcc addresses, either individually or all at once:

$m->addTo('jim@example.com');
$m->addTo(array('dwight@example.com', 'angela@example.com'));
$m->addCC('holly@example.com');
$m->addCC(array('kelly@example.com', 'ryan@example.com'));
$m->addBCC('michael@example.com');
$m->addBCC(array('kevin@example.com', 'oscar@example.com'));

These calls are cumulative, so in the above example, three addresses end up in each of the To, CC, and BCC fields.

You can also set one or more Reply-To addresses:

$m->addReplyTo('andy@example.com');
$m->addReplyTo(array('stanley@example.com', 'erin@example.com'));

You can set a return path address:

$m->setReturnPath('noreply@example.com');

You can use the contents of a file as the message text instead of a string:

$m->setMessageFromFile('/path/to/some/file.txt');
// or from a URL, if allow_url_fopen is enabled:
$m->setMessageFromURL('http://example.com/somefile.txt');

If you have both a text version and an HTML version of your message, you can set both:

$m->setMessageFromString($text, $html);

Or from a pair of files instead:

$m->setMessageFromFile($textfilepath, $htmlfilepath);
// or from a URL, if allow_url_fopen is enabled:
$m->setMessageFromURL($texturl, $htmlurl);

Remember that setMessageFromString, setMessageFromFile, and setMessageFromURL are mutually exclusive. If you call more than one, then whichever call you make last will be the message used.

Finally, if you need to specify the character set used in the subject or message:

$m->setSubjectCharset('ISO-8859-1');
$m->setMessageCharset('ISO-8859-1');

The default is UTF-8 if you do not specify a charset, which is usually the right setting. You can read more information in the SES API documentation.


My version of this library does not support the SendRawEmail call, which means you cannot send emails with attachments or custom headers; however, Daniel Zahariev has forked the project and implemented this functionality. You can download it at his github project page.


Disclaimer: Although I worked for Amazon in the past, this class was neither produced, endorsed nor supported by Amazon.  I wrote this class as a personal project, just for fun.

319 thoughts on “Simple Email Service

  1. Ross

    Many, many thanks for this – a dream to use.

    I’ve spent 2 days trying to get ses-send-email.pl working but when I do sendmail -bv there seems to be an issue with not retuning my host name that I cannot get around.

    This on the other hand worked first time – you’ve saved my sanity!
    Thanks!

    Reply
    1. moorthy

      Hi

      I am troubling to change sender name instead of default user. can u help me how to use ses-send-email.pl?

      Reply
  2. chylvina

    Hi Dan, thanks for your great work. I am using in my website.

    I have one question. How can I use html markup in setMessageFromString.

    I tried:
    setMessageFromString(‘hello world! hello world!’);

    But the line break does not work.

    Thanks!

    Reply
  3. chylvina

    Sorry, the html markup can not be displayed.

    setMessageFromString(‘hello world! &lt#BR#&gt hello world!’);

    Reply
    1. Ericnyc

      Hey C, that works fine for me, but needs to be the 2nd arg to the function:

      $ses->setMessageFromString(‘text version or leave blank’,’html version <BR> hello world’);

      Reply
    2. kev

      i found the solution.
      $m->setMessageFromString(‘ ‘,’html stuff here’);
      leave a space in the first part. if there is no space, it wont work.

      Reply
  4. chylvina

    Hi, another issue here. It can reproduce some times.

    Notice: Undefined property: SimpleEmailServiceRequest::$resource in SimpleEmailServiceRequest->getResponse() (line 495 of /var/www/sites/all/libraries/ses.php).
    User warning: SimpleEmailService::sendEmail(): 7 couldn’t connect to host in SimpleEmailService->__triggerError() (line 361 of /var/www/sites/all/libraries/ses.php).

    Reply
    1. Lionel

      Hi Chylvina,

      I just saw your post regarding Amazon AWS SES about the errors you get (Undefined property: SimpleEmailServiceRequest::$resource, etc).

      All of a sudden, I get exactly the same! Did you find out how to solve this?

      Thanks for any hint!

      Greetings from Switzerland,
      Lionel

      Reply
  5. Damir Sečki

    Warning: SimpleEmailService::verifyEmailAddress(): 60 SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in D:\root\app\lib\3rd_party\amazon_ses.php on line 357

    Reply
  6. blout

    Hi Dan,

    is it possible to send email to unverified addresses?
    well, from a verified address of course (which is ours).
    Because we don’t want our users to be confused between our service and aws caused by another verification process. Really need your help. Thx

    Reply
  7. Alex Whittaker

    Thanks for code Dan, we have been using it for a few weeks and it runs nicely. My only thought is that it is pretty slow when cycling through a large list of email addresses – I get about 0.8 seconds per email which is a bit slow if you are hoping to reach an audience of millions! Have you given any thought to batching up the requests?

    Cheers,

    ..alex

    Reply
    1. Alex Whittaker

      Answering my own question, I guess BCC is probably the answer.

      Reply
      1. Mauricio

        You could make asynchronous requests to the page that sends a specific email. So in a CRON job you would fire like 10 asynchronous requests to a page that sends email.

        At least you don’t need to use BCC.

        Also, by using asynchronous requests, your script will finish in no time.

        Reply
      2. Douglas

        Hello, I have some speed issues also. The function sendEmail() takes a lot of time.

        I cannot use BCC, because each email is different (the name of the recipient is in the email).

        Do you have any idea how can I speed up the sendEmail() function?

        Reply
  8. Rakesh Bhatt

    Hi, Thank’s a lot for this post i will be soon using this in my web site but i have a problem that can i set the from name and reply name as well in mail header along withe the email id’s. I didn’t get any way to do that. Thank’s in advance

    Reply
    1. Dan

      Suppose you have a message object $m:

      $m->addTo('Joe Consumer <joe@example.com>');
      $m->setFrom('Customer Service <service@example.com>');

      Reply
      1. ron

        When i tried this
        $m->setFrom(‘Customer Service ‘);

        the mail is not able to send, there is no error though it’s just that the recipient will not receive the email

        but $m->setFrom(‘service@example.com’) works fine

        Any idea what’s the problem?

        Reply
        1. ron

          Strangely, the email is being taken out after post, notice below…

          $m->setFrom(‘Customer Service ‘);

          Reply
  9. Andrew

    I have made some modifications to handle sending S/MIME messages. If you are interested in having this merged in, email me.

    Reply
  10. Tomas

    Hi, if you want to make FROM name with diacritics, you have to use this way of setFrom:

    $m->setFrom(‘=?UTF-8?B?’.base64_encode(‘Sender name diacritics ěščřžýáí’).’?= ‘);

    Reply
    1. Tomas

      sorry, i did not put it into code tag, so it was cut. Home it will be complete now … there was missing email address like Dan defined on August 20, 2012 at 7:50 pm:


      $m->setFrom('=?UTF-8?B?'.base64_encode('Sender name diacritics ěščřžýáí').'?= ');

      Reply
  11. krishnaveni

    Notice: Undefined property: SimpleEmailServiceRequest::$resource in C:\wamp\www\TestApp\ses.php on line 491

    Warning: SimpleEmailService::verifyEmailAddress(): 60 SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in C:\wamp\www\TestApp\ses.php on line 357
    I am geeting this error plese help me on this

    Reply
  12. Deepak

    Hi Dan,

    Could you please tell us how to add Dear {username} , dynamically in email body content.

    Please tell us how to write code for that.

    Thanks.

    Reply
  13. JoeB

    I cant get this to work, i’ve tried the very first example:

    $ses = new SimpleEmailService(
    'XXXXXXXX', // Access Key
    'XXXXXXXX' // Secret Key
    );
    print_r($ses->listVerifiedEmailAddresses());
    exit();

    and i get this error:

    Notice: Undefined property: SimpleEmailServiceRequest::$resource in W:\Sites\lib\amazon-web-services\ses.class.php on line 492

    Warning: SimpleEmailService::listVerifiedEmailAddresses(): 60 SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in W:\Sites\lib\amazon-web-services\ses.class.php on line 358

    Any ideas?

    I’m running on my local machine for testing.

    Reply
    1. JoeB

      Call this directly after creating the SimpleEmailService object:


      $ses = new SimpleEmailService('xxx', 'yyy');

      $ses->enableVerifyPeer(false);

      // do something...

      This disables checking of the certificate.
      Also recommended to set the SSL version to 3, on line 456:


      curl_setopt($curl, CURLOPT_SSLVERSION, 3); // add this line
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, ($this->ses->verifyHost() ? 1 : 0));
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, ($this->ses->verifyPeer() ? 1 : 0));

      See here:

      http://dominiquedecooman.com/blog/solution-curl-webservice-curlesslcacert-60-peer-certificate-cannot-be-authenticated-known-ca-ce

      Reply
  14. deepti

    Getting following error:
    RequestExpired [Message] => Request timestamp: Mon, 05 Nov 2012 15:47:06 UTC expired. It must be within 300 secs/ of server time. ) [RequestId] => 0e7127b8-2780-11e2-9236-496b230ed80a ) [code] => 400

    Reply
        1. Dan

          If it’s a Linux server you can change the time using the “date” command, but you should probably set up ntp to automatically get the time set based on an authoritative server on the internet. Try googling some of that, it’s well beyond the scope of what I can help you with here 🙂

          Reply
          1. deepti

            Hi Dan,

            Thanks for the reply the time issue is resolved, in linux server there is provision to change the server time.

            But if I try to send HTML email it send the HTML instead of sending formatted email

            Any Idea.

            Thanks

            Reply
            1. Paul

              I too am experiencing HTML code in the emails. I am calling get_file_contents then replacing certain strings within it, ‘{RECIPIENT_NAME}’ for example, with data to personalize the email. But when I call setMessageFromString, I receive an email with HTML code displaying.

              Reply
  15. hari

    I am getting this error, pls help me..

    Severity: User Warning

    Message: SimpleEmailService::verifyEmailAddress(): Sender – InvalidClientTokenId: The security token included in the request is invalid Request Id: 703cb75d-2e43-11e2-b610-5db26ab2c27e

    Filename: mails/ses.php

    Line Number: 362

    Reply
      1. hari

        Ya this problem was solved yesterday only..that’s true credentials are wrong.
        Can we send bulk emails at once ? upto 50 or morethan 50?
        In sending bulk emails can we hide other mail id’s in ‘To’. Only who are the getting the mail that person mail id have to see by that person only.. it is possible .. help me..

        Reply
  16. Steven

    Hey,

    Is it possible to set ‘from name’..
    like “Steven ”
    $m->setFrom(‘Steven ‘);

    instead of

    $m->setFrom(‘my@email.com’);

    thanks

    Reply
  17. Omar A

    I’m not getting an error message (from SES) and no emails are sent. I have verified the domain and the email addresses I’m sending form on SES.

    Any Idea where can I find the error messages (nothing in the logs) or what could be the problem.

    Reply
    1. Dan

      If you dump the response to the API call, one of the elements of the array will be a request id. You can give that to the SES team, either on the forums or via Developer Support, and they can figure out what happened to the request.

      If you’re not getting a request id, and the response array doesn’t contain an error message either, then the request probably isn’t making it to the service.

      (Note that even error responses should include a request id.)

      Reply
    1. Dan

      Unfortunately the version of the library available on SourceForge does not support attachments.

      Reply
      1. Andre

        Dan – does that imply there is another version somewhere that does? 😉

        I would be very interested in it.

        Many thanks,
        Andre

        Reply
  18. Pingback: Amazon Simple Email Service 初步使用 | INHd

  19. Pingback: 10 Great Resources for Web Developers

  20. Mahendra

    I am using your class for sending emails through amazon SES. I wanted to know how I could implement unsubscribe from list.
    Is there any generic function to implement this..?? any suggestions will highly be appreciated.
    Thanks in advance.

    Reply
  21. thoman

    Hello
    this is my error

    Warning: SimpleEmailService::sendEmail(): Sender - AccessDenied: User: arn:aws:iam::187953140120:user/smpt1 is not authorized to perform: ses:SendEmail Request Id: 91e99735-6ebf-11e2-a326-fd935e19d85f in /home/fake/public_html/fake/amazon_ses_phpmailer/ses.php on line 363

    Reply
    1. Dan

      You’re using an IAM user that does not have permission to call the SendEmail API. You’ll need to add that permission to that IAM user (or talk to the person who gave you the credentials so they can do it).

      Reply
  22. andrew

    Why do you trigger user warnings instead to provide the error/response in the response itself ? I think that’s a stupid thing and perhaps you are stupid too .

    Reply
  23. Yuan

    Hi,
    I would like to pose a question about email header.

    If I want to use some header fields like “List-Unsubscribe”, “X-Complaints-To” and etc, what should I do? Could you give me some advice? Need I make some changes in “ses.php”?

    Thanks a lot!!

    Yuan

    Reply
    1. Yuan

      Sorry I am not careful when i read the article at the first time.
      I just found this sentence:

      This library does not support the SendRawEmail call, which means you cannot send emails with attachments or custom headers, and unfortunately I will be unable to add that support.

      So, I still want your advice about using header fields while programming in PHP.

      Thanks in advance.
      Yuan

      Reply
  24. Jon

    Wonderful bit of code, made my life much simpler! One question – is there a way to supply a “friendly” name as well as just an email address in the from field? In other words, an email client might display it as from “Customer Services” rather than “custservices@company.com”.

    Reply
    1. Dan

      If I remember correctly, you can specify a string like this:

      “Customer Services <custservices@company.com>”

      as the From address. (You can do the same for To/CC/BCC addresses as well.)

      Reply
      1. Jon

        Yes, you’re absolutely right. Whatever Amazon are paying you, it’s not enough!

        Reply
  25. Karol

    Hi,

    Sorry for my English,

    I have a problem with the script … When I run it sends the email, but it shows this error:

    Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in …

    Thanks for your help.

    regards,

    Karol

    Reply
    1. Dan

      You can ignore that error message. Or you could fix the settings it’s complaining about 🙂

      Reply
  26. Mohamed Alaa

    Hi Dan,

    Thank you for your amazing SES Class. It’s really very helpful.

    I just would like to know how to handle the errors in your class.

    let’s say i’m getting this error:

    Severity: User Warning

    Message: SimpleEmailService::sendEmail(): Sender - MessageRejected: Email address is not verified. Request Id: 4ae2b3bd-8676-11e2-ae73-3758a049155c

    Filename: app/ses.php
    Line Number: 363

    how could I catch it in my application?

    Thanks,
    Mohamed

    Reply
    1. Dan

      If you look at the response object to the sendEmail() call, you should see some metadata in it. Try this:

      print_r($ses->sendEmail(… params here …));

      You can have your code examine the response to see if it’s an error.

      Reply
  27. Marc-Antoine

    Hello,

    I am sure that your class is stable but it hasn’t been updated since 2011. I suppose the API was updated since then, so currently is there any issue or important missing functionality? Moreover, is there any specific reason to use the official SDK instead of your class (besides the attachment and raw sending capabilities)?

    Thanks a lot!

    Reply
    1. Dan

      The SES API has been updated since this class was released, but I don’t know the full list of newer features off the top of my head.

      One reason to use the official AWS SDK is that AWS supports the official SDK, and frequently releases bugfixes, improvements, and newer features. The SDK also supports a wide variety of services, not just SES.

      The feedback I’ve been given both here on this site and by e-mail is that some people find the official SDK to be less usable and/or too bulky compared to my SES class.

      Reply
  28. Navin

    After reading all post .I if am understanding right then there is not provision of attachments. Correct me if am wrong?

    Reply
    1. Will

      Nope. No Attachments. This Is A “Get You Going” Script… BUT SES Will Allow Attachments. If Anyone Needs A Sample, Hit Me Up.

      Reply
  29. Arshad

    Hello,
    i find this article very helpful but can anyone give me script for attachment too, thanks in advance

    Reply
  30. Feyisayo

    Thanks a lot for this. I have used it a number of times and it works.

    Thanks again.
    Feyisayo

    Reply
  31. Dave

    When I use do this:
    $htmlurl = ‘http://www.example.com/email.htm’;
    $m->setMessageFromURL($htmlurl);

    The email received is the raw html (I.e. all the tags are seen etc.) – How do I fix that?

    Email message body:
    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
    </head>

    <body>

    Hello world!!!!

    </body>
    </html>

    Reply
  32. hese

    Thanks for this awesome PHP class!

    For some reason, I cant get multiple “addBcc” addresses to work:

    $m->addTo(‘myemail@gmail.com’);
    $m->addBCC(array(‘my2ndemail@domain.com’, ‘my3rdemail@domain.com’));

    This will only send email to the first myemail@gmail.com address.

    Any ideas whats wrong?

    Reply
  33. HuangFei

    require_once(‘ses.php’);
    $ses = new SimpleEmailService(‘[access key]’, ‘[secret key]’);
    print_r($ses->verifyEmailAddress(‘aiernet@126.com’));

    above is my code,the flowing is display:

    Notice: Undefined property: SimpleEmailServiceRequest::$resource in F:\PHPnow-1.5.6\htdocs\amazonwms\SES\ses.php on line 491
    Warning: SimpleEmailService::verifyEmailAd

    please tell me why ???

    Reply
    1. Dan Post author

      You shouldn’t put your access key and secret key in forum or blog posts 🙂 I removed them, but I still strongly recommend you delete the keypair you are currently using and generate a new one.

      I think there’s a bug in the SES class somewhere. If the verifyEmailAddress call still works, don’t worry about it. Or, you could fix the warning!

      Reply
  34. budy

    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, ‘<' not found in C:\xampp\htdocs\email\ses.php on line 499

    Warning: simplexml_load_string() [function.simplexml-load-string]: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-376766033 in C:\xampp\htdocs\email\ses.php on line 499

    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\xampp\htdocs\email\ses.php on line 499

    Warning: SimpleEmailService::verifyEmailAddress(): Encountered an error: Array in C:\xampp\htdocs\email\ses.php on line 366

    Reply
  35. Kesava

    Hi there,
    I have peculiar problem,

    except sendEmail, all other functions are working properly.

    print_r($ses->listVerifiedEmailAddresses());
    print_r($ses->getSendQuota());
    print_r($ses->getSendStatistics());

    All the above functions returning values properly.

    My debug skills shows, sendEmail function is returning false from
    if($rest->error !== false)
    {

    $this->__triggerError(‘sendEmail’, $rest->error);
    print (“I am here “);
    return false;
    }

    Can someone throw light on this problem?

    Please note, I got production access to my SES.

    Thanks in advance
    Regards
    Kesava

    Reply
  36. Rajesh Bute

    Does anyone know that how to implement the amazon SNS service in php, basically i need notification whenever bounce happens so i can ignore next time.

    Thanks in advance!

    Reply
  37. Nikhil

    Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead in E:\ambitionME\local_server\Public\ses.php on line 456

    Notice: Undefined property: SimpleEmailServiceRequest::$resource in E:\ambitionME\local_server\Public\ses.php on line 491

    Warning: SimpleEmailService::getSendQuota(): 60 SSL certificate problem: unable to get local issuer certificate in E:\ambitionME\local_server\Public\ses.php on line 357

    i got these errors while executing following code:
    include_once(‘ses.php’);
    $con=new SimpleEmailService(“AKIAIL6PZPAZ7KZG7WHA”,”AtIr6VRyOoZu033vEHsSW4x3HPUMpFyeArIUCiVXaQOM”);
    print_r($con->getSendQuota());die();

    Reply
  38. abhishek

    Hey frnd,
    we have using this service.
    How can we send attachments with email ?
    thanks in advanced,
    🙂

    Reply
  39. L.Mohan Arun

    Hi,

    If I use
    $m->setFrom(‘user@mydomain.com’);

    the Sender Name shows up as ‘user’ when
    I receive the email in gmail.

    How can I set a “From Name:”?
    I checked ses.php and couldnt find something
    that will let me set up a ‘from’ sender name…

    Any guidance appreciated.

    Thanks,

    Reply
  40. Nrao

    verifyEmailAddress(‘[valid email addr]’));
    ?>
    Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead in E:\xampp\htdocs\email\ses.php on line 456
    Notice: Undefined property: SimpleEmailServiceRequest::$resource in E:\xampp\htdocs\email\ses.php on line 491
    Warning: SimpleEmailService::verifyEmailAddress(): 60 SSL certificate problem: unable to get local issuer certificate in E:\xampp\htdocs\email\ses.php on line 357

    plz help me out in gettin the access to send mail……
    thanks in advance

    Reply
    1. Willet

      Hi! I’m getting the exact same error. Did you ever discover the problem? Thanks!

      Reply
    2. mt

      Search for CURLOPT_SSL_VERIFYHOST in the ses code and update 1 : 0 to 2 : 0.

      Per php.met under CURLOPT_SSSL_VERIFYHOST: Support for value 1 removed in cURL 7.28.1.

      Reply
  41. Ishan

    Hiii dear,

    I have a problem occurring in the above code, i want your help.
    Please reply me if you have solution of my problem.

    And the problem is that “SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. ”

    And also tell me that why i am getting this type of problem…

    Reply
  42. Divine

    Hi,

    The function/class works perfectly until recently. We got internal server error when trying to send an email message with great body content length,example:

    Hi there,

    Sorry you were unable to make your scheduled free trial appointment today. Please have a look at your schedule and let us know when you’d like to rebook.

    Only 1 week left of our January Special!

    Please keep in mind when booking your next appointment that we appreciate notice when unable to make the day/time you select. We often bring in extra Trainers to accomodate multiple free trial appointments.

    Don’t miss out on the workout everyone is talking about & getting results from!

    See you soon!

    These are what we found in the error log.

    PHP Warning: SimpleEmailService::verifyEmailAddress(): 56 SSL read: error:00000000:lib(0):func(0):reason(0), errno 104 in /home/hit/public_html/includes/ses/ses.php on line 357

    PHP Warning: SimpleEmailService::sendEmail(): Sender – InvalidParameterValue: Illegal content.
    Request Id: a3db4db4-85ff-11e3-ae5e-a39300faa3b8
    in /home/hit/public_html/includes/ses/ses.php on line 363

    Any thoughts? please help us out. thank you.

    Reply
  43. David

    I have to create unique body text for each email (specific activation code etc.)

    How do I clear/replace the “To”, “Subject”, and “Body” data in the SimpleEmailServiceMessage() object?

    Reply
  44. Joydeep

    Where is the ses.php file? Do I need to download and save it in the web directory? Where do I download it from? The github page doesn’t have any ses.php.

    Reply
  45. Tsanko

    I’m sending email form verified email and verified domain but when “addTo(” is not verified domain or mail I’m getting

    Warning: SimpleEmailService::sendEmail(): Sender – MessageRejected: Email address is not verified. Request Id: e9ea3b28-33b0-11e4-81db-19c405f16db2 in /home/bgmailor/public_html/ses/SimpleEmailService.php on line 377

    My SES is not in sandbox

    Reply
  46. Rodrigo Valentim

    Pls, Where is the ses.php ????
    ses.php = SimpleEmailService.php?

    i get this error on execute class by command line

    addTo(‘XXX@XXXXX’);
    $m->setFrom(‘XXXX@XXXXX’);
    $m->setSubject(‘Hello, world!’);
    $m->setMessageFromString(‘This is the message body.’);

    print_r($ses->sendEmail($m));

    ?>

    [root@ip]# php test.php

    PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, ‘<' not found in /usr/share/php/php-aws-ses-master/src/SimpleEmailServiceRequest.php on line 142
    PHP Warning: simplexml_load_string(): 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-805484607 RwhQZGEsNkaNdeBn in /usr/share/php/php-aws-ses-master/src/SimpleEmailServiceRequest.php on line 142
    PHP Warning: simplexml_load_string(): ^ in /usr/share/php/php-aws-ses-master/src/SimpleEmailServiceRequest.php on line 142
    PHP Warning: SimpleEmailService::sendEmail(): Encountered an error: Array in /usr/share/php/php-aws-ses-master/src/SimpleEmailService.php on line 380

    Reply
  47. Matt

    Looks like this script is not caching “Email Address Not Verified” and fails with:

    Fatal error: Class ‘TL_Error’ not found in ses.php on line 364

    Any Idea why?

    Reply
  48. Mike

    I’ve used this tool for over a year with great success, then today (10/17/14) I get this error message:

    Warning: SimpleEmailService::sendEmail(): 35 Unknown SSL protocol error in connection to email.us-east-1.amazonaws.com:443 in ses.php on line 357

    The mail is not sent.

    Nothing has changed on my side. Here’s a simplified version of the code that produces the error: (it’s a direct copy from above)

    require_once(‘ses.php’);
    $ses = new SimpleEmailService(‘Access Key Here’, ‘Secret Key Here’);
    $ses->enableVerifyPeer(false);
    $m = new SimpleEmailServiceMessage();
    $m->addTo(‘toaddress@here.com’);
    $m->setFrom(‘fromaddress@here.com’);
    $m->setSubject(‘Hello, world!’);
    $m->setMessageFromString(‘This is the message body.’);

    print_r($ses->sendEmail($m));

    Any thoughts what would cause this or how to fix?

    thanks,

    Reply
    1. Ted

      Hi! I had the same problem.

      I added this line to line 449:

      curl_setopt($curl, CURLOPT_SSLVERSION, 4);

      Note, “4” instead of “3”. Now it works again!

      Reply
  49. John Paul

    Can anyone of you please tell how to set region in above code while sending mail

    Reply
    1. blavv

      This should’ve been documented, but you can specify the region as the third argument to the constructor like this:

      $ses = new SimpleEmailService(‘Access Key Here’, ‘Secret Key Here’, $region);

      for instance, if you’re on US West 2, then

      $region = ’email.us-west-2.amazonaws.com’;

      This argument is optional and set to US East 1 by default btw.

      should do.

      Reply
  50. Jeff A

    I’m having an issue where users doing this from Windows NT machines are getting multiple emails from Amazon. This doesn’t happen when they are on Macs, other Windows versions, or iPads. Any reason why this would be happening?

    Reply
  51. SM

    Just took a quick glance at this and seems to be what I want as I only need SES ability. I am confused though how we know if an email successfully sent if we want to do some logic on our side for success/failed.

    In the comments above you state:
    ————
    If you dump the response to the API call, one of the elements of the array will be a request id. You can give that to the SES team, either on the forums or via Developer Support, and they can figure out what happened to the request.

    If you’re not getting a request id, and the response array doesn’t contain an error message either, then the request probably isn’t making it to the service.

    (Note that even error responses should include a request id.)
    ————–

    So, according to this the response array always contains a request id regardless… if it contains a message id that means it succeeded? You also state the response array will contain the error message if there is one, but glancing at the code it wouldn’t appear so.

    Reply
  52. Mike

    Have been using this solution for 2 years. Absolutely wonderful. Until I upgraded to PHP 5.6. Now with every send, I get this error message:

    An error occurred in script ‘<>/ses.php’ on line
    533:
    Undefined property: stdClass::$body
    Date/Time: 9-9-2015 21:25:44
    Array
    (
    [curl] => Resource id #11
    [data] =>

    0000014fb5808a18-d5c8eaed-0b63-4742-b99f-a18be4ddf704-000000

    0086b897-5774-11e5-8a2a-655ed0ff9cf9

    )

    It runs just fine on PHP 5.4, but after upgrading to 5.6, I get this error. Can anyone help?

    Mike

    Reply
    1. Mike

      Providing a solution to my question…
      I moved to Daniel Zahariev’s code and the problem went away. The only change I made was to
      change this line:
      require_once(‘ses.php’);
      to this:
      require_once(‘SimpleEmailService.php’);
      require_once(‘SimpleEmailServiceMessage.php’);
      require_once(‘SimpleEmailServiceRequest.php’);

      Reply
  53. supplement

    How are you handling authorization… oauth? any ideas about oauth?

    I saw this portion of code..

    $auth = ‘AWS3-HTTPS AWSAccessKeyId=’.$this->ses->getAccessKey();
    $auth .= ‘,Algorithm=HmacSHA256,Signature=’.$this->__getSignature($date);
    $headers[] = ‘X-Amzn-Authorization: ‘ . $auth;

    Reply
  54. Twiddly

    Any update for Amazon’s new SES signature v4?

    Got a notice saying
    Amazon Simple Email Service is ending support for Signature Version 3 effective September 30, 2020

    Reply
  55. ghi

    PHP Warning: SimpleEmailService::verifyEmailAddress(): 23 Failed writing body (0 != 430) in awsmail/ses.php on line 357

    Reply
    1. zooli

      plz help me
      PHP Warning: SimpleEmailService::verifyEmailAddress(): 23 Failed writing body (0 != 430) in awsmail/ses.php on line 357

      Reply
  56. sefa

    PHP Fatal error: Call to undefined method SimpleEmailServiceMessage::setMessageTag() in rsrg/abc.php on line 72

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *