Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function send_email($to, $from_email, $from_name, $subject, $body,
  5. $is_html=false, $attachments=null) {
  6. global $smtp_host, $smtp_port, $smtp_user, $smtp_password;
  7. try {
  8. $email = new PHPMailer(true);
  9. if ($from_email === $smtp_user) {
  10. $email->isSMTP();
  11. $email->Host = $smtp_host;
  12. $email->Port = $smtp_port;
  13. $email->SMTPAuth = true;
  14. $email->Username = $smtp_user;
  15. $email->Password = $smtp_password;
  16. $email->SMTPSecure = 'tls';
  17. }
  18.  
  19. $email->CharSet = 'UTF-8';
  20. $email->From = $from_email;
  21. $email->FromName = $from_email;
  22. $email->Subject = $subject;
  23. $email->Body = $body;
  24. $email->AddAddress($to);
  25.  
  26. if ($is_html == true) {
  27. $email->IsHTML(true);
  28. $email->Encoding = 'base64';
  29. }
  30.  
  31. if ($attachments != null) {
  32. foreach ($attachments as $attachment) {
  33. $apath = $attachment["path"];
  34. $aname = $attachment["name"];
  35. $email->AddAttachment($apath , $aname);
  36. }
  37. }
  38.  
  39. $email->Send();
  40. $status = "success";
  41. }
  42. catch (phpmailerException $e) {
  43. $status = $e->errorMessage();
  44. }
  45. catch (Exception $e) {
  46. $status = $e->getMessage();
  47. }
  48. return $status;
  49. }
  50.  
  51. $email->DKIM_domain = 'mydomain.com';
  52. $email->DKIM_private = '/path/to/private_key';
  53. $email->DKIM_selector = 'default';
  54. $email->DKIM_passphrase = '1234567';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement