Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 = 'knowlensguestuser3@gmail.com';
- }
- $destination = array();
- $destination['ToAddresses'] = array($to);
- if($cc != '')
- {
- $cc = explode(',', $cc);
- $destination['CcAddresses'] = $cc;
- }
- if($bcc != '')
- {
- $bcc = explode(',', $bcc);
- $destination['BccAddresses'] = $bcc;
- }
- $replyTo = 'notifications@knowlens.com';
- $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.0n";
- $message.= 'Content-Type: multipart/mixed; boundary="aRandomString_with_signs_or_9879497q8w7r8number"';
- $message.= "nn";
- $message.= "--aRandomString_with_signs_or_9879497q8w7r8numbern";
- $message.= 'Content-Type: text/plain; charset="utf-8"';
- $message.= "n";
- $message.= "Content-Transfer-Encoding: 7bitn";
- $message.= "Content-Disposition: inlinen";
- $message.= "n";
- $message.= $body;
- $message.= "nn";
- $message.= "--aRandomString_with_signs_or_9879497q8w7r8numbern";
- $message.= "Content-ID: <77987_SOME_WEIRD_TOKEN_BUT_UNIQUE_SO_SOMETIMES_A_@domain.com_IS_ADDED>n";
- $message.= 'Content-Type: application/'.$filetype.'; name="'.$filename.'"';
- $message.= "n";
- $message.= "Content-Transfer-Encoding: base64n";
- $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. <notifications@knowlens.com>',
- // Destination is required
- 'Destination' => $destination,
- // Message is required
- 'RawMessage' => array(
- // Data is required
- 'Data' => base64_encode($message),
- ),
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement