Ejemplo 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);
 }
Ejemplo n.º 2
0
 public function testComposer()
 {
     $mail = new ezcMailComposer();
     $mail->from = new ezcMailAddress('*****@*****.**', 'Adrian Ripburger');
     $mail->addTo(new ezcMailAddress('*****@*****.**', 'Maureen Corley'));
     $mail->subject = "This is the subject of the example mail";
     $mail->plainText = "This is the body of the example mail.";
     $mail->build();
     $transport = new ezcMailMtaTransport();
     //        $transport->send( $mail );
 }
Ejemplo n.º 3
0
 private function send_password($email, $password)
 {
     $mail = new ezcMailComposer();
     $mail->from = new ezcMailAddress('*****@*****.**', 'Open Keidas');
     $mail->addTo(new ezcMailAddress($email, ''));
     $mail->subject = 'Open Keidas -tunnuksesi';
     $mail->plainText = "Hei,\n\nUusi Open Keidas-salasanasi on: {$password}\n\nVoit käyttää sitä kirjautuaksesi osoitteessa http://openkeidas.fi/mgd:login";
     $mail->build();
     $transport = new ezcMailMtaTransport();
     $transport->send($mail);
 }
Ejemplo n.º 4
0
 public static function onError(Exception $e = NULL)
 {
     echo JFExecutionHandler::BuildUserError($e);
     $mail = new ezcMailComposer();
     $mail->from = new ezcMailAddress('*****@*****.**', 'JetFuel Error Mailer');
     $mail->addTo(new ezcMailAddress('*****@*****.**', 'Blend Errors'));
     $mail->subject = "Error occured on " . $_SERVER['HTTP_HOST'];
     $mail->plainText = JFExecutionHandler::BuildPlainTextEmail($e);
     $mail->htmlText = JFExecutionHandler::BuildEmail($e);
     $mail->build();
     $transport = new ezcMailMtaTransport();
     $transport->send($mail);
 }
Ejemplo n.º 5
0
 /**
  * Constructs an empty ezcMailComposer object.
  *
  * @param ezcMailComposerOptions $options
  */
 public function __construct(ezcMailComposerOptions $options = null)
 {
     parent::__construct($options);
     $this->properties['charset'] = 'utf-8';
     $this->properties['subjectCharset'] = 'utf-8';
 }
Ejemplo n.º 6
0
<?php

require 'ezc-setup.php';
$mail = new ezcMailComposer();
// from and to addresses, and subject
$mail->from = new ezcMailAddress('*****@*****.**', 'John Doe');
$mail->addTo(new ezcMailAddress('*****@*****.**', 'Derick Rethans'));
$mail->subject = "Example of an HTML email with attachments";
// body: plain
$mail->plainText = "Here is the text version of the mail.";
// body: html
$mail->htmlText = <<<ENDHTML
<html>Here is the HTML version of your mail with an image: <img
src='file://{$dir}/consoletools-table.png'/></html>
ENDHTML;
// add an attachment
$mail->addAttachment("{$dir}/mail.php");
// send the mail
$transport = new ezcMailTransportSmtp('localhost', null, null, 2525);
$transport->send($mail);
Ejemplo n.º 7
0
 public function testWalkPartsForStreamFile()
 {
     // create a temporary file
     $tmpFile = tempnam(sys_get_temp_dir(), "stream");
     file_put_contents($tmpFile, "content");
     // create mail instance
     $mail = new ezcMailComposer();
     $mail->addAttachment($tmpFile);
     $mail->build();
     // create the testing context
     $context = new ezcMailPartWalkContext(function ($ctx, $part) {
         $this->assertInstanceOf('ezcMailStreamFile', $part);
     });
     $context->filter = ['ezcMailStreamFile'];
     // test it
     $mail->walkParts($context, $mail);
     // remove the temporary file
     @unlink($tmpFile);
 }
Ejemplo n.º 8
0
<?php

require_once 'tutorial_autoload.php';
// Create a new mail composer object
$mail = new ezcMailComposer();
// Specify the "from" mail address
$mail->from = new ezcMailAddress('*****@*****.**', 'Adrian Ripburger');
// Add one "to" mail address (multiple can be added)
$mail->addTo(new ezcMailAddress('*****@*****.**', 'Maureen Corley'));
// Specify the subject of the mail
$mail->subject = "This is the subject of the example mail";
// Specify the body text of the mail
$mail->plainText = "This is the body of the example mail.";
// Generate the mail
$mail->build();
// Create a new SMTP transport object with an SSLv3 connection.
// The port will be 465 by default, use the 4th argument to change it.
// Username and password (2nd and 3rd arguments) are left blank, which means
// the mail host does not need authentication.
// The 5th parameter is the $options object which specifies a SSLV3 connection
// (default is ezcMailSmtpTransport::CONNECTION_PLAIN).
$options = new ezcMailSmtpTransportOptions();
$options->connectionType = ezcMailSmtpTransport::CONNECTION_SSLV3;
$transport = new ezcMailSmtpTransport('mailhost.example.com', '', '', null, $options);
// The option can also be specified via the option property:
$transport->options->connectionType = ezcMailSmtpTransport::CONNECTION_SSLV3;
// Use the SMTP transport to send the created mail object
$transport->send($mail);
Ejemplo n.º 9
0
Archivo: app.php Proyecto: jeanvoye/utb
    static function register(&$message)
    {
        $db = ezcDbInstance::get();
        $ini = $GLOBALS['ini'];
        $maxLength = $ini->getSetting('TheWire', 'maxUsernameLength');
        $user_id = substr(preg_replace('/[^a-z]/', '', $_POST['user_id']), 0, $maxLength);
        $fullname = ucwords(strtolower(preg_replace('/[^a-zæøå ]/ui', '', $_POST['fullname'])));
        $jabber = preg_replace('/[^a-z.@]/', '', $_POST['jabber_name']);
        // check if the user already exists.
        $q = $db->createSelectQuery();
        $q->select('id')->from('user')->where($q->expr->eq('id', $q->bindValue($user_id)));
        $s = $q->prepare();
        $s->execute();
        $r = $s->fetchAll();
        if (count($r) > 0) {
            $message = "A user with username '{$user_id}' already exists.";
            return false;
        }
        // generate password
        mt_srand(base_convert($user_id, 36, 10) * microtime(true));
        $a = base_convert(mt_rand(), 10, 36);
        $b = base_convert(mt_rand(), 10, 36);
        $password = substr($b . $a, 1, 8);
        // create user
        $q = $db->createInsertQuery();
        $q->insertInto('user')->set('id', $q->bindValue($user_id))->set('jabber', $q->bindValue($jabber))->set('fullname', $q->bindValue($fullname))->set('password', $q->bindValue(md5($password)))->set('timezone', $q->bindValue($_POST['timezone']));
        $s = $q->prepare();
        $s->execute();
        // create user prefs
        $db = ezcDbInstance::get();
        $q = $db->createInsertQuery();
        $q->insertInto('user_pref')->set('user_id', $q->bindValue($user_id))->set('mail_type', $q->bindValue(0))->set('http_refresh', $q->bindValue(1))->set('jabber_type', $q->bindValue(1));
        $s = $q->prepare();
        $s->execute();
        // fetch settings
        $ini = $GLOBALS['ini'];
        $fromAddress = $ini->getSetting('TheWire', 'mailFrom');
        $mailDomain = $ini->getSetting('TheWire', 'mailDomain');
        $jabberUser = $ini->getSetting('jabber', 'user');
        $jabberDomain = $ini->getSetting('jabber', 'domain');
        $url = $ini->getSetting('TheWire', 'installDomain');
        // send registration mail
        $m = new ezcMailComposer();
        $m->from = new ezcMailAddress($fromAddress, 'The Wire');
        $m->addTo(new ezcMailAddress($user_id . '@' . $mailDomain, $fullname));
        $m->subject = 'Registration for The Wire';
        $m->plainText = <<<ENDT
Hello!

We've created a user account. Your password is:
\t{$password}

You can now login at http://{$url}.
Please change your password to something you want it to be.

In order to make jabber integration work, please follow the following
procedure:

- Add the user "{$jabberUser}@{$jabberDomain}" to your jabber account.
- Send a message like "hello" to this new user.
- The jabber user will now authenticate you and ask for your
  authorization as well.
- Authorize the jabber user so that it can send messages to you.

regards,
The Wire.

ENDT;
        $m->build();
        $s = new ezcMailMtaTransport();
        $s->send($m);
        $message = "A user account has been created, see your mail to find further instructions.";
        return true;
    }
Ejemplo n.º 10
0
 public function testEncodedHeaders()
 {
     $m = new ezcMailComposer();
     $m->from = new ezcMailAddress('*****@*****.**', 'Frøya', 'utf-8');
     $m->addTo(new ezcMailAddress('*****@*****.**', 'Óðinn', 'utf-8'));
     $m->subject = "Blót";
     $m->subjectCharset = 'utf-8';
     $this->transport->send($m);
     $this->assertEquals("=?utf-8?Q?Bl=C3=B3t?=", $m->getHeader('Subject'));
 }
<?php

require_once 'tutorial_autoload.php';
// Create a new mail composer object
$mail = new ezcMailComposer();
// Specify the "from" mail address
$mail->from = new ezcMailAddress('*****@*****.**', 'John Doe');
// Add one "to" mail address (multiple can be added)
$mail->addTo(new ezcMailAddress('*****@*****.**', 'Cindy Doe'));
// Specify the subject of the mail
$mail->subject = "Example of an HTML email with attachments";
// Specify the plain text of the mail
$mail->plainText = "Here is the text version of the mail. This is displayed if the client can not understand HTML";
// Specify the html text of the mail
$mail->htmlText = "<html>Here is the HTML version of your mail with an image: <img src='file://path_to_image.jpg' /></html>";
// Add a file as an attachment to the mail
$mail->addFileAttachment('path_to_attachment.file');
// Add a string as an attachment to the mail, with 'filename' as the name of the attachment in the mail
$contents = 'contents of the attachment';
// can be a binary string, eg. contents of an image file
$mail->addStringAttachment('filename', $contents);
// Build the mail object
$mail->build();
// Create a new MTA transport object
$transport = new ezcMailMtaTransport();
// Use the MTA transport to send the created mail object
$transport->send($mail);
Ejemplo n.º 12
0
 public function testContentDispositionSimpleAttach()
 {
     $mail = new ezcMailComposer();
     $mail->from = new ezcMailAddress('*****@*****.**');
     $mail->subject = "яверасфăîţâşåæøåöä";
     $mail->addTo(new ezcMailAddress('*****@*****.**'));
     $contentDisposition = new ezcMailContentDispositionHeader('attachment', 'яверасфăîţâşåæøåöä.jpg');
     $mail->plainText = 'xxx';
     $mail->addAttachment(dirname(__FILE__) . "/parts/data/fly.jpg", null, null, null, $contentDisposition);
     $mail->build();
     $msg = $mail->generate();
     $set = new ezcMailVariableSet($msg);
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $parts = $mail[0]->fetchParts();
     // for issue #13038, displayFileName was added to contentDisposition
     $contentDisposition->displayFileName = 'яверасфăîţâşåæøåöä.jpg';
     $this->assertEquals($contentDisposition, $parts[1]->contentDisposition);
 }
<?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->addFileAttachment('/home/me/details.png', 'image', 'png');
$message->addStringAttachment('extra.txt', 'Some text', 'text/plain');
$message->build();
$sender = new ezcMailMtaTransport();
$sender->send($message);
<?php

require_once 'tutorial_autoload.php';
// Create a new mail composer object
$mail = new ezcMailComposer();
// Specify the "from" mail address
$mail->from = new ezcMailAddress('*****@*****.**', 'John Doe');
// Add one "to" mail address (multiple can be added)
$mail->addTo(new ezcMailAddress('*****@*****.**', 'Cindy Doe'));
// Specify the subject of the mail
$mail->subject = "Example of an HTML email with attachments";
// Specify the plain text of the mail
$mail->plainText = "Here is the text version of the mail. This is displayed if the client can not understand HTML";
// Specify the html text of the mail
$mail->htmlText = "<html>Here is the HTML version of your mail with an image: <img src='file://path_to_image.jpg' /></html>";
// Add an attachment to the mail
$mail->addAttachment('path_to_attachment.file');
// Build the mail object
$mail->build();
// Create a new MTA transport object
$transport = new ezcMailMtaTransport();
// Use the MTA transport to send the created mail object
$transport->send($mail);
Ejemplo n.º 15
0
 if (!stripos($html, "unsubscribe")) {
     $cli->output("Did not find unsubscribe url");
     continue;
 }
 // Genereate plain text mail
 $cmd = "/usr/local/bin/premailer -r --mode txt " . escapeshellarg($url) . "2>&1";
 $return = exec($cmd, $output, $return_var);
 $text = implode("\n", $output);
 if ($return_var != 0) {
     $cli->output("Error executing command: {$cmd}");
     $cli->output(var_dump($output));
     continue;
 }
 unset($output);
 // Send mail
 $mail = new ezcMailComposer();
 $mail->charset = $charset;
 $mail->subjectCharset = $charset;
 $mail->subject = $subject;
 $mail->htmlText = $html;
 $mail->plainText = $text;
 $mail->from = $from_email;
 $mail->addTo(new ezcMailAddress($delivery->attribute('email'), '', $charset));
 $mail->setHeader("Reply-To", $reply_email->__toString(), $charset);
 $mail->build();
 try {
     $mail_transport->send($mail);
 } catch (Exception $e) {
     $cli->output('Error sending mail: ' . $e->getMessage());
 }
 $delivery->setAttribute('state', 'sent');
Ejemplo n.º 16
0
<?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;
$html = '<html><body><b>Hooray!</b> New PHP Version!</body></html>';
$message->htmlText = $html;
$message->build();
$sender = new ezcMailMtaTransport();
$sender->send($message);
 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);
 }