Guest User

Untitled

a guest
Nov 26th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public function sendmail($maildata, $to, $subject, $attachments = [])
  2. {
  3. require_once(APPPATH.'third_party/PHPMailer/PHPMailerAutoload.php');
  4. //Create a new PHPMailer instance
  5. $mail = new PHPMailer;
  6.  
  7. $mail->SMTPOptions = array(
  8. 'ssl' => array(
  9. 'verify_peer' => false,
  10. 'verify_peer_name' => false,
  11. 'allow_self_signed' => true
  12. )
  13. );
  14.  
  15. //Tell PHPMailer to use SMTP
  16. $mail->isSMTP();
  17. //Enable SMTP debugging
  18. // 0 = off (for production use)
  19. // 1 = client messages
  20. // 2 = client and server messages
  21. $mail->SMTPDebug = 0;
  22. //Ask for HTML-friendly debug output
  23. $mail->Debugoutput = 'html';
  24. $mail->Host = 'SMTP_HOST';
  25. $mail->Port = 587;
  26. $mail->SMTPSecure = 'tls';
  27. $mail->SMTPAuth = true;
  28. $mail->XMailer = 'YOUR_SITENAME';
  29. $mail->Username = "YOUR_SMTP_USERNAME";
  30. $mail->Password = "YOUR_SMTP_PASSWORD";
  31. $mail->setFrom(EMAIL_FROM_ADDRESS, YOUR_SITENAME);
  32. $recipients = explode(',', $to);
  33. foreach($recipients as $email)
  34. {
  35. $mail->AddAddress($email);
  36. }
  37. $mail->Subject = $subject;
  38. $mail->msgHTML($maildata);
  39. if(!empty($attachments)){
  40. foreach($attachments as $attachVal){
  41. $mail->addAttachment($attachVal);
  42. }
  43. }
  44. //send the message, check for errors
  45. if(!$mail->send()) {
  46. //echo $mail->ErrorInfo;exit;
  47. $return = false;
  48. } else {
  49. $return = true;
  50. }
  51.  
  52. return $return;
  53. }
Add Comment
Please, Sign In to add comment