/** * Create an email message. The ppMailer plugin class is * basically a factory class that returns a ppMailer_Message object * that can be manipulated before being sent. * * @return object */ function create($to = '', $subject = '', $body = '', $fromemail = '', $fromname = '') { $this->_load(); $swift = new ppMailer_Message(); if (defined('SMTP_HOST') && SMTP_HOST != '') { require_once DIR_FS_PRONTO . DS . 'extlib' . DS . 'swift' . DS . 'Swift' . DS . 'Connection' . DS . 'SMTP.php'; $port = defined('SMTP_PORT') ? SMTP_PORT : 25; $mode = SWIFT_SMTP_ENC_OFF; if (defined('SMTP_ENC')) { switch (SMTP_ENC) { case 'TLS': $mode = SWIFT_SMTP_ENC_TLS; break; case 'SSL': $mode = SWIFT_SMTP_ENC_SSL; break; } } $conn = new Swift_Connection_SMTP(SMTP_HOST, $port, $mode); } else { require_once DIR_FS_PRONTO . DS . 'extlib' . DS . 'swift' . DS . 'Swift' . DS . 'Connection' . DS . 'NativeMail.php'; $conn = new Swift_Connection_NativeMail(); } if (defined('SMTP_USER') && SMTP_USER != '') { $conn->setUsername(SMTP_USER); $conn->setPassword(SMTP_PASS); } $swift->swift = new Swift($conn); $swift->message = new Swift_Message($subject); $swift->message->setCharset(defined('CHARSET') ? CHARSET : 'UTF-8'); if ($body) { $swift->add_text_part($body); } $swift->recipients = new Swift_RecipientList(); // we need a non-empty default $swift->set_from(defined('ADMIN_EMAIL') ? ADMIN_EMAIL : '*****@*****.**'); if ($fromemail) { $swift->set_from($fromemail, $fromname); } if (is_array($to)) { foreach ($to as $email => $name) { if (is_numeric($email)) { $swift->add_recipient($name); } else { $swift->add_recipient($email, $name); } } } else { if ($to) { $swift->add_recipient($to); } } return $swift; }
public function test220ResponseIsSentWhenStoppedAndStarted() { $connection = new Swift_Connection_NativeMail(); $connection->start(); $this->assertPattern("~^220\\b~", $connection->read()); $connection->write("foo"); $this->assertNoPattern("~^220\\b~", $connection->read()); $connection->stop(); $connection->start(); $this->assertPattern("~^220\\b~", $connection->read()); }
/** * Builds a Swift_Connection depending on the type (native, smtp, sendmail, multi, rotator) * Params depend on the connection type * * - native: * additional_params * * - smtp: * server (*) * port * encryption (SSL, TLS, or OFF) * authentication: * username (*) * password * timeout * requires_ehlo * * - sendmail: * command * flags * timeout * requires_ehlo * * - multi: * connections: * connection_name1: * type * params * connection_name2: * type * params * etc... * requires_ehlo * * - rotator: * connections: * connection_name1: * type * params * connection_name2: * type * params * etc... * requires_ehlo * * (*) Mandatory ! * * @param string $type * @param array $params * @return Swift_Connection */ protected static function getConnection($type, $params = array()) { switch ($type) { case 'native': $connection = new Swift_Connection_NativeMail(); if (@$params['additional_params']) { $connection->setAdditionalMailParams($params['additional_params']); } break; case 'smtp': if (!@$params['encryption']) { $params['encryption'] = 'OFF'; } $encryption = constant('Swift_Connection_SMTP::ENC_' . $params['encryption']); $connection = new Swift_Connection_SMTP($params['server'], @$params['port'], $encryption); if (@$params['authentication']) { $connection->setUsername(@$params['authentication']['username']); $connection->setPassword(@$params['authentication']['password']); } if (@$params['timeout']) { $connection->setTimeout($params['timeout']); } if (@$params['requires_ehlo']) { $connection->setRequiresEHLO(true); } break; case 'sendmail': $connection = new Swift_Connection_Sendmail(); if (@$params['command']) { $connection->setCommand($params['command']); } if (@$params['flags']) { $connection->setFlags($params['flags']); } if (@$params['timeout']) { $connection->setTimeout($params['timeout']); } if (@$params['requires_ehlo']) { $connection->setRequiresEHLO(true); } break; case 'multi': $connection = new Swift_Connection_Multi(); foreach ($params['connections'] as $id => $conn_info) { $connection->addConnection(self::getConnection($conn_info['type'], $conn_info['params'])); } if (@$params['requires_ehlo']) { $connection->setRequiresEHLO(true); } break; case 'rotator': $connection = new Swift_Connection_Multi(); foreach ($params['connections'] as $id => $conn_info) { $connection->addConnection(self::getConnection($conn_info['type'], $conn_info['params'])); } if (@$params['requires_ehlo']) { $connection->setRequiresEHLO(true); } break; } return $connection; }