Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public function sendTestEmail()
  2. {
  3. if ($this->RequestHandler->isPost() && isset($_POST['serverId'])) {
  4.  
  5. $hostData = $this->MailSender->find('first', array(
  6. 'conditions' => array(
  7. 'id' => $_POST['serverId']
  8. )
  9. ));
  10. App::import('Vendor', 'nmail/phpmailer');
  11. try {
  12. $mailer = new phpmailer(true);
  13.  
  14. if ($hostData['MailSender']['loginemail'] === 'false') {
  15. $mailer->IsMail();
  16. } else {
  17. $mailer->IsSMTP();
  18. }
  19.  
  20. $mailer->SMTPAuth = $hostData['MailSender']['loginemail'] === 'false' ? false : true;
  21. $mailer->IsHTML(true);
  22.  
  23. switch ($hostData['MailSender']['secure']) {
  24. case 1:
  25. $mailer->SMTPSecure = 'tls';
  26. break;
  27. case 2:
  28. $mailer->SMTPSecure = 'ssl';
  29. break;
  30. case 3:
  31. $mailer->AuthType = 'NTLM';
  32. $mailer->Realm = $email_info[0][0]['realm'];
  33. $mailer->Workstation = $email_info[0][0]['workstation'];
  34. }
  35.  
  36. $mailer->SMTPDebug = 1;
  37. $mailer->From = $hostData['MailSender']['email'];
  38. $mailer->FromName = $hostData['MailSender']['name'];
  39. $mailer->Host = $hostData['MailSender']['smtp_host'];
  40. $mailer->Port = intval($hostData['MailSender']['smtp_port']);
  41. $mailer->Username = $hostData['MailSender']['username'];
  42. $mailer->Password = $hostData['MailSender']['password'];
  43. $mailer->AddAddress($_POST['email']);
  44. $mailer->Subject = "Test message";
  45. $mailer->Body = 'Hello, this smtp server is verified!';
  46. $mailer->Send();
  47. echo '1';
  48. } catch (phpmailerException $e) {
  49. echo $e->errorMessage();
  50. }
  51. exit;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement