Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 /**
  * Returns an ezcMail corresponding to the parsed message.
  * You can specify an alternate class using the $class parameter, if you
  * extended ezcMail.
  *
  * @param string $class Class to instanciate instead of ezcMail.
  * @return ezcMail
  */
 public function finish($class = "ezcMail")
 {
     $mail = new $class();
     $mail->setHeaders($this->headers->getCaseSensitiveArray());
     ezcMailPartParser::parsePartHeaders($this->headers, $mail);
     // from
     if (isset($this->headers['From'])) {
         $mail->from = ezcMailTools::parseEmailAddress($this->headers['From']);
     }
     // to
     if (isset($this->headers['To'])) {
         $mail->to = ezcMailTools::parseEmailAddresses($this->headers['To']);
     }
     // cc
     if (isset($this->headers['Cc'])) {
         $mail->cc = ezcMailTools::parseEmailAddresses($this->headers['Cc']);
     }
     // bcc
     if (isset($this->headers['Bcc'])) {
         $mail->bcc = ezcMailTools::parseEmailAddresses($this->headers['Bcc']);
     }
     // subject
     if (isset($this->headers['Subject'])) {
         $mail->subject = ezcMailTools::mimeDecode($this->headers['Subject']);
         $mail->subjectCharset = 'utf-8';
     }
     // message ID
     if (isset($this->headers['Message-Id'])) {
         $mail->messageID = $this->headers['Message-Id'];
     }
     // Return-Path
     if (isset($this->headers['Return-Path'])) {
         $mail->returnPath = ezcMailTools::parseEmailAddress($this->headers['Return-Path']);
     }
     if ($this->bodyParser !== null) {
         $mail->body = $this->bodyParser->finish();
     }
     return $mail;
 }
Exemplo n.º 3
0
 public function testParseEmailAddressLocalEncoding()
 {
     $add = ezcMailTools::parseEmailAddress('Test äöää <*****@*****.**>', 'iso-8859-1');
     $this->assertEquals('Test äöää', $add->name);
     $this->assertEquals('*****@*****.**', $add->email);
 }
 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);
 }
Exemplo n.º 5
0
<?php

require_once 'tutorial_autoload.php';
$mailAddresses = array(new ezcMailAddress('*****@*****.**', 'Jøhn Doe', 'ISO-8859-1'), new ezcMailAddress('*****@*****.**', 'Jane Doe'));
$addresses = '=?ISO-8859-1?B?SsO4aG4gRG9l?= <*****@*****.**>, Jane Doe <*****@*****.**';
// Convert ezcMailAddress to string representation
var_dump(ezcMailTools::composeEmailAddress($mailAddresses[0]));
var_dump(ezcMailTools::composeEmailAddresses($mailAddresses));
// Convert string to ezcMailAddress
var_dump(ezcMailTools::parseEmailAddress($addresses));
var_dump(ezcMailTools::parseEmailAddresses($addresses));
// Validate an email address (with a regular expression, without checking for MX records)
$isValid = ezcMailTools::validateEmailAddress('*****@*****.**');
// Validate an email address with MX records check.
// MX record checking does not work on Windows due to the lack of getmxrr()
// and checkdnsrr() PHP functions. The ezcBaseFunctionalityNotSupportedException
// is thrown in this case.
// set this to your mail server, it is used in a
// 'HELO SMTP' command to validate against MX records
ezcMailTools::$mxValidateServer = 'your.mail.server';
// set this to a mail address such as '*****@*****.**', it is used in a
// 'MAIL FROM' SMTP command to validate against MX records
ezcMailTools::$mxValidateAddress = '*****@*****.**';
$isValid = ezcMailTools::validateEmailAddress('*****@*****.**', true);
// Create a new mail object
$mail = new ezcMail();
$mail->from = $mailAddresses[1];
$mail->addTo($mailAddresses[0]);
$mail->subject = "Top secret";
// Use the lineBreak() method
$mail->body = new ezcMailText("Confidential" . ezcMailTools::lineBreak() . "DO NOT READ");