Guest User

Untitled

a guest
Dec 16th, 2017
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. public static function mailTo($recipients)
  2. {
  3. $f3 = Base::instance();
  4. $edit = $f3->get('editTrue');
  5. $user = AclHelper::getCurrentUser();
  6. $template= new Template;
  7. if(isset($edit))
  8. {
  9. $mailBody = $template->render('leave/requestEdit.html');
  10. }
  11. else
  12. {
  13. $mailBody= $template->render('leave/emailTemp.html');
  14. }
  15.  
  16. // When true, PHPMailer returns exceptions
  17. $mail = new PHPMailer(true);
  18. try {
  19. $mail->isSMTP(); // Set mailer to use SMTP
  20. $mail->isHTML(true);
  21.  
  22. $mail->addAddress($user['email']);
  23. $mail->addAddress("malakar.rakesh1993@gmail.com");
  24.  
  25. // foreach($recipients as $recipient){
  26. // $mail->addCC($recipient);
  27. // }
  28.  
  29. $mail->SMTPAuth = true; // authentication enabled
  30. $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
  31. $mail->Host = "smtp.gmail.com";
  32. $mail->Port = 465; // or 587
  33. $mail->Username = "malakar.rakesh1993@gmail.com";
  34. $mail->Password = "abcd";
  35.  
  36. // $mail->Host = $f3->get('GBD.smtp.host'); // Specify main and backup SMTP servers
  37. $mail->setFrom($user['email']);
  38.  
  39. $userFullName = trim(ucfirst($user['firstname'])) . " " . trim(ucfirst($user['lastname']));
  40. $mail->FromName = $userFullName;
  41. $mail->Body = $f3->get('message');
  42. $mail->Body .="<br>". $mailBody;
  43.  
  44. if(isset($edit))
  45. {
  46. $mail->AltBody = '';
  47. }
  48. else
  49. {
  50. $mail->AltBody = 'Hello Team,<br>I would like to request leave for the leave dates specified as follows.
  51. Application Date:' . $f3->get('issuedDate') . '<br>Leave requested from:' . $f3->get('leaveFrom') . '<br>Leave requested to:' . $f3->get('leaveTo') . '<br>Leave Description:' . $f3->get('leaveDescription') . 'Leave Type:' . $f3->get('leaveType').'<br><br>Hoping for a positive response.<br><br> Thank you.';
  52. }
  53.  
  54. $mail->Subject = 'Updates on leave date applied';
  55.  
  56. $mailStatus = (boolean)$mail->send();
  57.  
  58. if ($mailStatus === true) {
  59. return $mail;
  60. }
  61. } catch (phpmailerException $e) {
  62. $response = array(
  63. 'status'=>'error',
  64. 'message'=>'Got some error while sending emails',
  65. 'exceptions'=>$e->getMessage()
  66. );
  67. return $response;
  68.  
  69. } catch (Exception $e) {
  70. $response = array(
  71. 'status'=>'error',
  72. 'message'=>'Got some error while sending emails',
  73. 'exceptions'=>$e->getMessage()
  74. );
  75.  
  76. return $response;
  77. }
  78. }
  79.  
  80. This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing
Add Comment
Please, Sign In to add comment