Advertisement
Guest User

Untitled

a guest
May 31st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. /*
  2. * Function sendRawMail() is used to send mails to user with attachments
  3. */
  4. public function sendRawMail($subject, $body='', $to, $cc = '',$bcc = '', $filetype,$filename,$filepath)
  5. {
  6.  
  7. $domain = explode('@', $to);
  8. if (count($domain) > 1 && $domain[1] == 'guest.com') {
  9. $to = 'knowlensguestuser3@gmail.com';
  10. }
  11.  
  12. $destination = array();
  13. $destination['ToAddresses'] = array($to);
  14. if($cc != '')
  15. {
  16. $cc = explode(',', $cc);
  17. $destination['CcAddresses'] = $cc;
  18. }
  19. if($bcc != '')
  20. {
  21. $bcc = explode(',', $bcc);
  22. $destination['BccAddresses'] = $bcc;
  23. }
  24.  
  25.  
  26. $replyTo = 'notifications@knowlens.com';
  27.  
  28. $client = SesClient::factory(array(
  29. 'key' => Yii::$app->params['aws.id'],
  30. 'secret' => Yii::$app->params['aws.secret'],
  31. 'region' => 'us-east-1',
  32. ));
  33.  
  34. $message= "To: ".$to."n";
  35. $message.= "From: ".$replyTo."n";
  36. $message.= "Subject: ".$subject."n";
  37. $message.= "MIME-Version: 1.0n";
  38. $message.= 'Content-Type: multipart/mixed; boundary="aRandomString_with_signs_or_9879497q8w7r8number"';
  39. $message.= "nn";
  40. $message.= "--aRandomString_with_signs_or_9879497q8w7r8numbern";
  41. $message.= 'Content-Type: text/plain; charset="utf-8"';
  42. $message.= "n";
  43. $message.= "Content-Transfer-Encoding: 7bitn";
  44. $message.= "Content-Disposition: inlinen";
  45. $message.= "n";
  46. $message.= $body;
  47. $message.= "nn";
  48. $message.= "--aRandomString_with_signs_or_9879497q8w7r8numbern";
  49. $message.= "Content-ID: <77987_SOME_WEIRD_TOKEN_BUT_UNIQUE_SO_SOMETIMES_A_@domain.com_IS_ADDED>n";
  50. $message.= 'Content-Type: application/'.$filetype.'; name="'.$filename.'"';
  51. $message.= "n";
  52. $message.= "Content-Transfer-Encoding: base64n";
  53. $message.= 'Content-Disposition: attachment; filename="'.$filename.'"';
  54. $message.= "n";
  55. $message.= base64_encode(file_get_contents($filepath));
  56. $message.= "n";
  57. $message.= "--aRandomString_with_signs_or_9879497q8w7r8number--n";
  58.  
  59. $result = $client->SendRawEmail(array(
  60. // Source is required
  61. 'Source' => '​​​​Knowlens Solutions Pvt. Ltd. <notifications@knowlens.com>',
  62. // Destination is required
  63. 'Destination' => $destination,
  64. // Message is required
  65. 'RawMessage' => array(
  66. // Data is required
  67. 'Data' => base64_encode($message),
  68. ),
  69.  
  70. ));
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement