2015-08-14 197 views
0

我試圖建立我的亞馬遜SES與PHP和我導致了已經在這裏所做的這一發現github上:https://github.com/daniel-zahariev/php-aws-ses如何正確建立亞馬遜SES

我有困難就前往工作,我不確定我做錯了什麼。有經驗的人能給我一些關於進一步做什麼的見解嗎?它說它正在發送電子郵件,但是當我檢查我的收件箱時,什麼都沒有發生。以下是我的代碼:

require_once('src/SimpleEmailService.php'); 
require_once('src/SimpleEmailServiceMessage.php'); 
require_once('src/SimpleEmailServiceRequest.php'); 
$ses = new SimpleEmailService('myaccessid', 'myaccesskey'); 
$m = new SimpleEmailServiceMessage(); 
$m->addTo('[email protected]'); 
$m->setFrom('Name <[email protected]>'); 
$m->setSubject('You have got Email!'); 
$m->setMessageFromString('Your message'); 
$ses->sendEmail($m); 
+1

您是否驗證了您的發件人電子郵件地址? http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html – BestPractices

+0

你好,這是正確的。我驗證了發件人的地址。雖然我沒有驗證我的DKIM,也不確定是否真的需要它發送電子郵件。 – chronotrigga

+0

我也嘗試將addTo發送到驗證的電子郵件,但我仍然沒有收到電子郵件。 – chronotrigga

回答

2

如果您不願意使用任何創建的類,只是直接使用SDK即可,這裏是一個工作代碼;

// Include AWS SDK for PHP 

$path = $_SERVER['DOCUMENT_ROOT']; 
$path .= "/php/awssdk/aws-autoloader.php"; 
require($path); 

// Instantiate an SES instance 

$client = SesClient::factory(array(
      'key' => 'your key', 
      'secret' => 'your secret', 
      'region' => 'your region' 
     )); 

//Now that you have the client ready, you can build the message 
    $msg = array(); 
    $msg['Source'] = "verified email"; 
    //ToAddresses must be an array 
    $msg['Destination']['ToAddresses'][] = "verified email"; 

    $msg['Message']['Subject']['Data'] = "Your Subject"; 
    $msg['Message']['Subject']['Charset'] = "UTF-8"; 
    $msg['Message']['Body']['Html']['Data'] ="Your message"; 
    $msg['Message']['Body']['Html']['Charset'] = "UTF-8"; 
    $result = $client->sendEmail($msg); 
    if($result) { 
     echo "Email Sent"; 
    }