示例#1
0
 /**
  * Establishes a SMTP connection
  * @return \System\Email\SMTP The SMTP connection
  */
 private static final function getSMTPConnection()
 {
     if (!defined('EMAILSYSTEM_SMTP_HOST') || !defined('EMAILSYSTEM_SMTP_PORT') || !defined('EMAILSYSTEM_SMTP_TIMEOUT') || !defined('EMAILSYSTEM_SMTP_PASSWORD') || !defined('EMAILSYSTEM_SMTP_HANDLEMAILS') || !defined('EMAILSYSTEM_SMTP_USERNAME')) {
         throw new \System\Error\Exception\SystemException('Please set the EMAILSYSTEM_SMTP_HOST, EMAILSYSTEM_SMTP_PORT, EMAILSYSTEM_SMTP_TIMEOUT, EMAILSYSTEM_SMTP_PASSWORD, EMAILSYSTEM_SMTP_HANDLEMAILS and EMAILSYSTEM_SMTP_USERNAME config directives');
     }
     $server = new \System\HTTP\Request\Server();
     $smtp = new \System\Email\SMTP(EMAILSYSTEM_SMTP_HOST, EMAILSYSTEM_SMTP_PORT, EMAILSYSTEM_SMTP_TIMEOUT);
     $smtp->sendCommand('EHLO ' . $server->get('SERVER_ADDR'));
     $smtp->sendCommand('AUTH LOGIN');
     $smtp->sendCommand(base64_encode(EMAILSYSTEM_SMTP_USERNAME));
     $smtp->sendCommand(base64_encode(EMAILSYSTEM_SMTP_PASSWORD));
     return $smtp;
 }