Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2. // Replace us-west-2 with the AWS Region you're using for Amazon SES.
  3. define('REGION','us-east-1');
  4.  
  5. // require REQUIRED_FILE;
  6. require '/home/ubuntu/vendor/autoload.php';
  7.  
  8. use Aws\Ses\SesClient;
  9. use Aws\Ses\Exception\SesException;
  10.  
  11. $client = SesClient::factory(array(
  12. 'version'=> 'latest',
  13. 'region' => REGION
  14. ));
  15.  
  16. $dest_email_id = 'verified@mail.com';
  17. $source_email_id = 'anotherverified@mail.com';
  18. $replyto_email_id = 'anotherverified@mail.com';
  19.  
  20. $subject = 'my subject';
  21.  
  22. $csv_file = dirname(__FILE__) .'/uploads/filename.csv';
  23. $file_size = filesize($csv_file);
  24. $handle = fopen($csv_file, "r");
  25.  
  26. $content = fread($handle, $file_size);
  27.  
  28. $content = chunk_split(base64_encode($content));
  29. $header = "";
  30. $message = "some body text.";
  31.  
  32. $uid = md5(uniqid(time()));
  33. $header = "From: ".$source_email_id." <".$source_email_id.">\r\n";
  34. $header .= "Reply-To: ".$replyto_email_id."\r\n";
  35. $header .= "To: ".$dest_email_id."\r\n";
  36. $header .= "Subject: ".$subject."\r\n";
  37. $header .= "MIME-Version: 1.0\r\n";
  38. $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  39. $header .= "This is a multi-part message in MIME format.\r\n";
  40. $header .= "--".$uid."\r\n";
  41. $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
  42. $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  43. $header .= $message."\r\n\r\n";
  44. $header .= "--".$uid."\r\n";
  45. $header .= "Content-Type: text/csv; name=\"".$csv_file."\"\r\n";
  46.  
  47. $header .= "Content-Transfer-Encoding: base64\r\n";
  48. $header .= "Content-Disposition: attachment; filename=\"".$csv_file."\"\r\n\r\n";
  49. $header .= $content."\r\n\r\n";
  50. $header .= "--".$uid."--";
  51.  
  52. $msg['RawMessage']['Data'] = base64_encode($header);
  53. $msg['RawMessage']['Source']= $source_email_id;
  54. $msg['RawMessage']['Destinations'] = array($dest_email_id);
  55. fclose($handle);
  56.  
  57.  
  58. try{
  59. $result = $client->sendRawEmail($msg);
  60. error_log("Email sent! Message ID: ".$result->get('MessageId')."\n");
  61.  
  62. } catch (SesException $e) {
  63. error_log("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n");
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement