Guest User

Untitled

a guest
Nov 5th, 2017
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static function smtpmailer($to, $from, $from_name, $subject, $body) {
  2. $mail = new PHPMailer(); // create a new object
  3. $mail->IsSMTP(); // enable SMTP
  4. $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
  5. $mail->SMTPAuth = true; // authentication enabled
  6. $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  7. $mail->Host = 'smtp.gmail.com';
  8. $mail->Port = 465;
  9. $mail->Username = "someemail@gmail.com";
  10. $mail->Password = "somepassword";
  11. $mail->SetFrom($from, $from_name);
  12. $mail->Subject = $subject;
  13. $mail->Body = $body;
  14. if (is_string($to)) {
  15. $to = array($to);
  16. }
  17. foreach ($to as $t) {
  18. $mail->AddAddress($t);
  19. }
  20. if(!$mail->Send()) {
  21. $error = 'Mail error: '.$mail->ErrorInfo;
  22. return false;
  23. } else {
  24. $error = 'Message sent!';
  25. return true;
  26. }
  27. }
Add Comment
Please, Sign In to add comment