function sendMail(eZMail $mail) { $ini = eZINI::instance(); $parameters = array(); $parameters['host'] = $ini->variable('MailSettings', 'TransportServer'); $parameters['helo'] = $ini->variable('MailSettings', 'SenderHost'); $parameters['port'] = $ini->variable('MailSettings', 'TransportPort'); $parameters['connectionType'] = $ini->variable('MailSettings', 'TransportConnectionType'); $user = $ini->variable('MailSettings', 'TransportUser'); $password = $ini->variable('MailSettings', 'TransportPassword'); if ($user and $password) { $parameters['auth'] = true; $parameters['user'] = $user; $parameters['pass'] = $password; } /* If email sender hasn't been specified or is empty * we substitute it with either MailSettings.EmailSender or AdminEmail. */ if (!$mail->senderText()) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'AdminEmail'); } eZMail::extractEmail($emailSender, $emailSenderAddress, $emailSenderName); if (!eZMail::validate($emailSenderAddress)) { $emailSender = false; } if ($emailSender) { $mail->setSenderText($emailSender); } } $excludeHeaders = $ini->variable('MailSettings', 'ExcludeHeaders'); if (count($excludeHeaders) > 0) { $mail->Mail->appendExcludeHeaders($excludeHeaders); } $options = new ezcMailSmtpTransportOptions(); if ($parameters['connectionType']) { $options->connectionType = $parameters['connectionType']; } $smtp = new ezcMailSmtpTransport($parameters['host'], $user, $password, $parameters['port'], $options); // If in debug mode, send to debug email address and nothing else if ($ini->variable('MailSettings', 'DebugSending') == 'enabled') { $mail->Mail->to = array(new ezcMailAddress($ini->variable('MailSettings', 'DebugReceiverEmail'))); $mail->Mail->cc = array(); $mail->Mail->bcc = array(); } // send() from ezcMailSmtpTransport doesn't return anything (it uses exceptions in case // something goes bad) try { eZPerfLogger::accumulatorStart('mail_sent'); $smtp->send($mail->Mail); eZPerfLogger::accumulatorStop('mail_sent'); } catch (ezcMailException $e) { eZPerfLogger::accumulatorStop('mail_send'); eZDebug::writeError($e->getMessage(), __METHOD__); return false; } // return true in case of no exceptions return true; }
public static function send($to, $subject, $body, $options = array()) { $siteINI = eZINI::instance('site.ini'); $i18nINI = eZINI::instance('i18n.ini'); $transport = $siteINI->variable('MailSettings', 'Transport'); $charset = $i18nINI->variable('CharacterSettings', 'Charset'); $emailSender = $siteINI->variable('MailSettings', 'EmailSender'); if (!$emailSender) { $emailSender = $siteINI->variable('MailSettings', 'AdminEmail'); } if ($transport == 'SMTP') { $mailTransport = new ezcMailSmtpTransport($siteINI->variable('MailSettings', 'TransportServer'), $siteINI->variable('MailSettings', 'TransportUser'), $siteINI->variable('MailSettings', 'TransportPassword'), $siteINI->variable('MailSettings', 'TransportPort')); } else { eZDebug::writeError('Only SMTP Transport supported', 'jajNewsletterSubscription::sendConfirmationMail'); throw new Exception('Only SMTP Transport supported'); } $mail = new ezcMailComposer(); $mail->charset = $charset; $mail->subjectCharset = $charset; $mail->subject = $subject; $mail->htmlText = $body; $mail->from = ezcMailTools::parseEmailAddress($emailSender, $charset); $mail->addTo(new ezcMailAddress($to, '', $charset)); $mail->build(); $mailTransport->send($mail); }
function sendMail(ezcMail $mail) { $ini = eZINI::instance(); $parameters = array(); $parameters['host'] = $ini->variable('MailSettings', 'TransportServer'); $parameters['helo'] = $ini->variable('MailSettings', 'TransportServer'); $parameters['port'] = $ini->variable('MailSettings', 'TransportPort'); $parameters['connectionType'] = $ini->variable('MailSettings', 'TransportConnectionType'); $user = $ini->variable('MailSettings', 'TransportUser'); $password = $ini->variable('MailSettings', 'TransportPassword'); if ($user and $password) { $parameters['auth'] = true; $parameters['user'] = $user; $parameters['pass'] = $password; } $options = new ezcMailSmtpTransportOptions(); if ($parameters['connectionType']) { $options->connectionType = $parameters['connectionType']; } $smtp = new ezcMailSmtpTransport($parameters['host'], $user, $password, $parameters['port'], $options); try { $smtp->send($mail); return true; } catch (ezcMailException $e) { eZDebug::writeError("Error sending SMTP mail: " . $e->getMessage(), 'eZSMTPTransport::sendMail'); echo "SMTP ERROR: " . $e->getMessage(); return false; } return false; }
<?php $message = new ezcMailComposer(); $message->from = new ezcMailAddress('*****@*****.**'); $message->addTo(new ezcMailAddress('*****@*****.**', 'Adam')); $message->subject = 'New Version of PHP Released!'; $body = 'Go to http://www.php.net and download it today!'; $message->plainText = $body; $message->build(); $host = 'smtpauth.example.com'; $username = '******'; $password = '******'; $port = 587; $smtpOptions = new ezcMailSmtpTransportOptions(); $smtpOptions->preferredAuthMethod = ezcMailSmtpTransport::AUTH_LOGIN; $sender = new ezcMailSmtpTransport($host, $username, $password, $port, $smtpOptions); $sender->send($message);
public function testConnectionPlain() { $this->skipIfNotInNetwork(self::HOST_SSL, self::PORT_SSL); try { $smtp = new ezcMailSmtpTransport(self::HOST_SSL, self::USER_SSL, self::PASS_SSL, null, array('connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN)); $this->mail->subject = __CLASS__ . ':' . __FUNCTION__; $smtp->send($this->mail); } catch (ezcMailTransportException $e) { $this->fail($e->getMessage()); } }
public function testAuthPlainWrongPassword() { try { $smtp = new ezcMailSmtpTransport(self::HOST_PLAIN, self::USER_PLAIN, 'wrong password', self::PORT_PLAIN, array('preferredAuthMethod' => ezcMailSmtpTransport::AUTH_PLAIN)); $this->mail->subject = __CLASS__ . ' - ' . __FUNCTION__; $smtp->send($this->mail); $this->fail('Expected message was not thrown.'); } catch (ezcMailTransportException $e) { } }
<?php require_once 'tutorial_autoload.php'; // Create an SMTP transport and demand NTLM authentication. // Username and password must be specified, otherwise no authentication // will be attempted. // If NTLM authentication fails, an exception will be thrown. // See the ezcMailSmtpTransport class for a list of supported methods. $options = new ezcMailSmtpTransportOptions(); $options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM; $transport = new ezcMailSmtpTransport('mailhost.example.com', 'username', 'password', null, $options); // The option can also be specified via the option property: $transport->options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM; // Use the SMTP transport to send the created mail object $transport->send($mail);
function sendConfirmationMail($list) { $tpl = eZTemplate::factory(); $template = 'design:jaj_newsletter/subscription/mail/confirm.tpl'; $siteINI = eZINI::instance('site.ini'); $i18nINI = eZINI::instance('i18n.ini'); $transport = $siteINI->variable('MailSettings', 'Transport'); $charset = $i18nINI->variable('CharacterSettings', 'Charset'); $emailSender = $siteINI->variable('MailSettings', 'EmailSender'); if (!$emailSender) { $emailSender = $siteINI->variable('MailSettings', 'AdminEmail'); } if ($transport == 'SMTP') { $mailTransport = new ezcMailSmtpTransport($siteINI->variable('MailSettings', 'TransportServer'), $siteINI->variable('MailSettings', 'TransportUser'), $siteINI->variable('MailSettings', 'TransportPassword'), $siteINI->variable('MailSettings', 'TransportPort')); } else { eZDebug::writeError('Only SMTP Transport supported', 'jajNewsletterSubscription::sendConfirmationMail'); throw new Exception('Only SMTP Transport supported'); } $tpl->setVariable('subscription', $this); $tpl->setVariable('list', $list); $tpl->setVariable('hostname', eZSys::hostname()); $templateResult = $tpl->fetch($template); $subject = "Please confirm your newsletter subscription"; if ($tpl->hasVariable('subject')) { $subject = $tpl->variable('subject'); } $mail = new ezcMailComposer(); $mail->charset = $charset; $mail->subjectCharset = $charset; $mail->subject = $subject; $mail->plainText = $templateResult; $mail->from = ezcMailTools::parseEmailAddress($emailSender, $charset); $mail->addTo(new ezcMailAddress($this->Email, $this->Name, $charset)); $mail->build(); $mailTransport->send($mail); }