Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function sendTestEmail()
- {
- if ($this->RequestHandler->isPost() && isset($_POST['serverId'])) {
- $hostData = $this->MailSender->find('first', array(
- 'conditions' => array(
- 'id' => $_POST['serverId']
- )
- ));
- App::import('Vendor', 'nmail/phpmailer');
- try {
- $mailer = new phpmailer(true);
- if ($hostData['MailSender']['loginemail'] === 'false') {
- $mailer->IsMail();
- } else {
- $mailer->IsSMTP();
- }
- $mailer->SMTPAuth = $hostData['MailSender']['loginemail'] === 'false' ? false : true;
- $mailer->IsHTML(true);
- switch ($hostData['MailSender']['secure']) {
- case 1:
- $mailer->SMTPSecure = 'tls';
- break;
- case 2:
- $mailer->SMTPSecure = 'ssl';
- break;
- case 3:
- $mailer->AuthType = 'NTLM';
- $mailer->Realm = $email_info[0][0]['realm'];
- $mailer->Workstation = $email_info[0][0]['workstation'];
- }
- $mailer->SMTPDebug = 1;
- $mailer->From = $hostData['MailSender']['email'];
- $mailer->FromName = $hostData['MailSender']['name'];
- $mailer->Host = $hostData['MailSender']['smtp_host'];
- $mailer->Port = intval($hostData['MailSender']['smtp_port']);
- $mailer->Username = $hostData['MailSender']['username'];
- $mailer->Password = $hostData['MailSender']['password'];
- $mailer->AddAddress($_POST['email']);
- $mailer->Subject = "Test message";
- $mailer->Body = 'Hello, this smtp server is verified!';
- $mailer->Send();
- echo '1';
- } catch (phpmailerException $e) {
- echo $e->errorMessage();
- }
- exit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement