Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. require_once dirname(__DIR__) . '/vendor/autoload.php';
  6.  
  7. use Simples\Mailer\PHPMailer;
  8. use Exception;
  9.  
  10. /**
  11. * @param string $address
  12. * @param string $subject
  13. * @param string $message
  14. * @param string $attachment (null)
  15. * @return bool
  16. * @throws Exception
  17. */
  18. function mail($address, $subject, $message, $attachment = null)
  19. {
  20. $mail = new PHPMailer;
  21.  
  22. $mail->Host = __SMTP_HOST__;
  23. $mail->Port = __SMTP_PORT__;
  24. $mail->SMTPSecure = __SMTP_SECURE__;
  25.  
  26. $mail->SMTPAuth = true;
  27. $mail->Username = __SMTP_USERNAME__;
  28. $mail->Password = __SMTP_PASSWORD__;
  29.  
  30. $mail->isSMTP();
  31.  
  32. $mail->setFrom(__SMTP_FROM__);
  33. $mail->addAddress($address);
  34. $mail->CharSet="utf-8";
  35. $mail->Subject = $subject;
  36. $mail->Body = $message;
  37. $mail->MsgHTML($message);
  38. $mail->IsHTML(true);
  39. if ($attachment && isset($attachment['path']) && isset($attachment['name'])) {
  40. $mail->addAttachment($attachment['path'], $attachment['name']);
  41. }
  42. if (!$mail->send()) {
  43. throw new Exception($mail->ErrorInfo);
  44. }
  45. return true;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement