Q:

Again: sending mail (through php) from an EC2 instance

I have seen lots of discussion on the problem of sending mail from an amazon EC2 instance using php's mail function.  None of the suggestions have worked with me.  
Here is my setup: 

I have ubuntu EC2 instance.  
I followed the steps on Amazon's SES to install postfix using the credentials that were created for me.  I tried both stunnel and direct methods.  
I used swiftmail transport to send my mail according to this.  The transport function for sending a mail returns 0 delivered.  
I used php mail just by itself and it returns true.  However, no mail is delivered not even in spam.  

By the way I'm not using the production service with SES.  The limits are fine with me, I just want it to work.  
I suspect I'm not being authenticated properly and I don't see why.  I tried to telnet ...amazonaws.com 25 and it gets connected.  But when I tried the command Mail From: ... in telnet, it says authentication is required.  
I have already thought of an alternative: sendgrid.  Too expensive for my use. 
Any thoughts?  

A:

Here is how I used Sendgrid to send mail from an EC2 instance using PHP: 

Sign up for a Sendgrid account.  You will receive a username and password to use for sending emails.  Also, Sendgrid will manually verify your account (possibly to prevent spam).  
Install PHP curl library in ubuntu: sudo apt-get install php5-curl.  
Use this PHP code to send email: 
$url = 'http://sendgrid.com/';
$user = 'sendgrid_user';
$pass = 'sendgrid_password'; 

$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'to'        => $dest_addr,
    'subject'   => $subject,
    'html'      => $body,
    //'text'      => 'testing body',
    'from'      => $from_addr,
  );

$request =  $url. 'api/mail.send.json';

$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// obtain response
$response = curl_exec($session);

//If the result is {"message":"success"}, then the mail is sent.   
curl_close($session);

