/** * Connect to Mail server * * @param array $config * @return boolean */ public function connect(array $config) { // Create the Transport $this->mailer = new \Swift_SmtpTransport($config['server'], $config['port'], sizeof($config['secure']) > 0 ? $config['secure'] : null); $this->mailer->setUsername($config['username']); $this->mailer->setPassword($config['password']); $this->mailer->start(); return $this->mailer->isStarted(); }
public function execute(Request $request, $function) { switch ($function) { case 'verify-smtp': $smtp = new \Swift_SmtpTransport($request->input('smtp-server'), $request->input('smtp-port'), $request->input('smtp-ssl')); $smtp->setUsername($request->input('smtp-username')); $smtp->setPassword($request->input('smtp-password')); $smtp->start(); $this->ajax_result['errno'] = 0; $this->ajax_result['html'] = 'OK'; $this->ajax_result['smtp'] = $smtp->isStarted(); // $this -> ajax_result['errno'] = time() % 2; // $this -> ajax_result['errmsg'] = 'chujnia jakas sie wydazyla'; // $this -> ajax_result['html'] = 'chujnia jakas sie wydazyla'; break; } echo json_encode($this->ajax_result); }
/** * Connect to Mail server * * @param array $config * @throws \RuntimeException * @return \Swift_SmtpTransport */ public function connect(array $config) { // save config $this->config = $config; try { if (!$this->connect) { $this->connect = new \Swift_SmtpTransport($config['server'], $config['port'], $config['socket']); $this->connect->setUsername($config['username']); $this->connect->setPassword($config['password']); $this->connect->start(); } if ($this->connect->isStarted() === false) { throw new MailException('Mail connection failed! Check configurations'); } return $this; } catch (\Exception $e) { throw new MailException($e->getMessage()); } }