amazon web services - How to Send file as attachment using PHP AWS SES latest SDK -


i trying send email file attachment using php aws ses latest sdk, got answer here works on older version of aws sdk not on current one.

aws provide 2 api method sendemail , sendrawemail, sendrawemail used send file attachment email.

so below updated code latest aws sdk 3.33

require __dir__ . '/aws/vendor/autoload.php'; $s3_config = [     'region' => 'us-east-1',     'version' => 'latest',     'credentials' => [         'key' => '<keyxxx>',         'secret' => '<secretxxx>'     ] ]; $aws = new \aws\sdk($s3_config); $client = $aws->createses(); $content = ""; $filename = ""; $mailto = "to@test.com" $content = file_get_contents($file); $content = chunk_split(base64_encode($content)); $filename = basename($file); $subject = "test email"; $finfo = finfo_open(fileinfo_mime_type); $fileinfo_mime_type = finfo_file($finfo, $file); try {     $separator = md5(time());     $separator_multipart = md5($subject . time());     $message = "mime-version: 1.0\n";     $message .= "subject: $subject\n";     $message .= "from: test name <from@test.com>\n";     $message .= "to: $mailto\n";     $message .= "content-type: multipart/mixed; boundary=\"$separator_multipart\"\n";     $message .= "\n--$separator_multipart\n";      $message .= "content-type: multipart/alternative; boundary=\"$separator\"\n";     $message .= "\n--$separator\n";     $message .= "content-type: text/plain; charset=\"utf-8\"\n";     $message .= "\n$body\n";     $message .= "\n--$separator--\n";      $message .= "--$separator_multipart\n";     $message .= "content-type: $fileinfo_mime_type; name=\"$filename\"\n";     $message .= "content-disposition: attachment; filename=\"$filename\"\n";     $message .= "content-transfer-encoding: base64\n";     $message .= "$content\n";     $message .= "--$separator_multipart--";      $result = $client->sendrawemail([         'rawmessage' => [             'data' => $message         ]     ]);     echo "\nemail sent\n"; } catch (\exception $e) {     echo $e->getmessage(); } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -