I am trying to send pdf attachments in mail using amazon SES sendmail() function in php . I have written a function which takes MIME type as content and send a mail. But I am not able to send attachment in the mail. the file paths and all the other values are seems perfect.
The functions code is as follows :
/*
* Function sendRawMail() is used to send mails to user with attachments
*/
public function sendRawMail($subject, $body='', $to, $cc = '',$bcc = '', $filetype,$filename,$filepath)
{
$domain = explode('@', $to);
if (count($domain) > 1 && $domain[1] == 'guest.com') {
$to = '[email protected]';
}
$destination = array();
$destination['ToAddresses'] = array($to);
if($cc != '')
{
$cc = explode(',', $cc);
$destination['CcAddresses'] = $cc;
}
if($bcc != '')
{
$bcc = explode(',', $bcc);
$destination['BccAddresses'] = $bcc;
}
$replyTo = '[email protected]';
$client = SesClient::factory(array(
'key' => Yii::$app->params['aws.id'],
'secret' => Yii::$app->params['aws.secret'],
'region' => 'us-east-1',
));
$message= "To: ".$to."\n";
$message.= "From: ".$replyTo."\n";
$message.= "Subject: ".$subject."\n";
$message.= "MIME-Version: 1.0\n";
$message.= 'Content-Type: multipart/mixed; boundary="aRandomString_with_signs_or_9879497q8w7r8number"';
$message.= "\n\n";
$message.= "--aRandomString_with_signs_or_9879497q8w7r8number\n";
$message.= 'Content-Type: text/plain; charset="utf-8"';
$message.= "\n";
$message.= "Content-Transfer-Encoding: 7bit\n";
$message.= "Content-Disposition: inline\n";
$message.= "\n";
$message.= $body;
$message.= "\n\n";
$message.= "--aRandomString_with_signs_or_9879497q8w7r8number\n";
$message.= "Content-ID: \<[email protected]_IS_ADDED\>\n";
$message.= 'Content-Type: application/'.$filetype.'; name="'.$filename.'"';
$message.= "\n";
$message.= "Content-Transfer-Encoding: base64\n";
$message.= 'Content-Disposition: attachment; filename="'.$filename.'"';
$message.= "\n";
$message.= base64_encode(file_get_contents($filepath));
$message.= "\n";
$message.= "--aRandomString_with_signs_or_9879497q8w7r8number--\n";
$result = $client->SendRawEmail(array(
// Source is required
'Source' => 'Knowlens Solutions Pvt. Ltd. <[email protected]>',
// Destination is required
'Destination' => $destination,
// Message is required
'RawMessage' => array(
// Data is required
'Data' => base64_encode($message),
),
));
}
Mail is successfully sent to the user, but without attachment. Please help.