Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Replace us-west-2 with the AWS Region you're using for Amazon SES.
- define('REGION','us-east-1');
- // require REQUIRED_FILE;
- require '/home/ubuntu/vendor/autoload.php';
- use Aws\Ses\SesClient;
- use Aws\Ses\Exception\SesException;
- $client = SesClient::factory(array(
- 'version'=> 'latest',
- 'region' => REGION
- ));
- $dest_email_id = 'verified@mail.com';
- $source_email_id = 'anotherverified@mail.com';
- $replyto_email_id = 'anotherverified@mail.com';
- $subject = 'my subject';
- $csv_file = dirname(__FILE__) .'/uploads/filename.csv';
- $file_size = filesize($csv_file);
- $handle = fopen($csv_file, "r");
- $content = fread($handle, $file_size);
- $content = chunk_split(base64_encode($content));
- $header = "";
- $message = "some body text.";
- $uid = md5(uniqid(time()));
- $header = "From: ".$source_email_id." <".$source_email_id.">\r\n";
- $header .= "Reply-To: ".$replyto_email_id."\r\n";
- $header .= "To: ".$dest_email_id."\r\n";
- $header .= "Subject: ".$subject."\r\n";
- $header .= "MIME-Version: 1.0\r\n";
- $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
- $header .= "This is a multi-part message in MIME format.\r\n";
- $header .= "--".$uid."\r\n";
- $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
- $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
- $header .= $message."\r\n\r\n";
- $header .= "--".$uid."\r\n";
- $header .= "Content-Type: text/csv; name=\"".$csv_file."\"\r\n";
- $header .= "Content-Transfer-Encoding: base64\r\n";
- $header .= "Content-Disposition: attachment; filename=\"".$csv_file."\"\r\n\r\n";
- $header .= $content."\r\n\r\n";
- $header .= "--".$uid."--";
- $msg['RawMessage']['Data'] = base64_encode($header);
- $msg['RawMessage']['Source']= $source_email_id;
- $msg['RawMessage']['Destinations'] = array($dest_email_id);
- fclose($handle);
- try{
- $result = $client->sendRawEmail($msg);
- error_log("Email sent! Message ID: ".$result->get('MessageId')."\n");
- } catch (SesException $e) {
- error_log("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement