Author: Marcus Bointon (Synchro/coolbru) (phpmailer@synchromedia.co.uk)
Author: Jim Jagielski (jimjag) (jimjag@gmail.com)
Author: Andy Prevost (codeworxtech) (codeworxtech@users.sourceforge.net)
Author: Brent R. Matzelle (original founder)
Esempio n. 1
6
 /**
  * Creates an activation entry and sends email to user
  * @param int $uid
  * @param string $email
  * @param string $type
  * @param boolean $sendmail = NULL
  * @return boolean
  */
 protected function addRequest($uid, $email, $type, &$sendmail)
 {
     $return['error'] = true;
     if ($type != "activation" && $type != "reset") {
         $return['message'] = $this->lang["system_error"] . " #08";
         return $return;
     }
     // if not set manually, check config data
     if ($sendmail === NULL) {
         $sendmail = true;
         if ($type == "reset" && $this->config->emailmessage_suppress_reset === true) {
             $sendmail = false;
             $return['error'] = false;
             return $return;
         }
         if ($type == "activation" && $this->config->emailmessage_suppress_activation === true) {
             $sendmail = false;
             $return['error'] = false;
             return $return;
         }
     }
     $query = $this->dbh->prepare("SELECT id, expire FROM {$this->config->table_requests} WHERE uid = ? AND type = ?");
     $query->execute(array($uid, $type));
     if ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
         $expiredate = strtotime($row['expire']);
         $currentdate = strtotime(date("Y-m-d H:i:s"));
         if ($currentdate < $expiredate) {
             $return['message'] = $this->lang["reset_exists"];
             return $return;
         }
         $this->deleteRequest($row['id']);
     }
     if ($type == "activation" && $this->getBaseUser($uid)['isactive'] == 1) {
         $return['message'] = $this->lang["already_activated"];
         return $return;
     }
     $key = $this->getRandomKey(20);
     $expire = date("Y-m-d H:i:s", strtotime($this->config->request_key_expiration));
     $query = $this->dbh->prepare("INSERT INTO {$this->config->table_requests} (uid, rkey, expire, type) VALUES (?, ?, ?, ?)");
     if (!$query->execute(array($uid, $key, $expire, $type))) {
         $return['message'] = $this->lang["system_error"] . " #09";
         return $return;
     }
     $request_id = $this->dbh->lastInsertId();
     if ($sendmail === true) {
         // Check configuration for SMTP parameters
         $mail = new PHPMailer();
         $mail->CharSet = $this->config->mail_charset;
         if ($this->config->smtp) {
             $mail->isSMTP();
             $mail->Host = $this->config->smtp_host;
             $mail->SMTPAuth = $this->config->smtp_auth;
             if (!is_null($this->config->smtp_auth)) {
                 $mail->Username = $this->config->smtp_username;
                 $mail->Password = $this->config->smtp_password;
             }
             $mail->Port = $this->config->smtp_port;
             if (!is_null($this->config->smtp_security)) {
                 $mail->SMTPSecure = $this->config->smtp_security;
             }
         }
         $mail->From = $this->config->site_email;
         $mail->FromName = $this->config->site_name;
         $mail->addAddress($email);
         $mail->isHTML(true);
         if ($type == "activation") {
             $mail->Subject = sprintf($this->lang['email_activation_subject'], $this->config->site_name);
             $mail->Body = sprintf($this->lang['email_activation_body'], $this->config->site_url, $this->config->site_activation_page, $key);
             $mail->AltBody = sprintf($this->lang['email_activation_altbody'], $this->config->site_url, $this->config->site_activation_page, $key);
         } else {
             $mail->Subject = sprintf($this->lang['email_reset_subject'], $this->config->site_name);
             $mail->Body = sprintf($this->lang['email_reset_body'], $this->config->site_url, $this->config->site_password_reset_page, $key);
             $mail->AltBody = sprintf($this->lang['email_reset_altbody'], $this->config->site_url, $this->config->site_password_reset_page, $key);
         }
         if (!$mail->send()) {
             $this->deleteRequest($request_id);
             $return['message'] = $this->lang["system_error"] . " #10";
             return $return;
         }
     }
     $return['error'] = false;
     return $return;
 }
Esempio n. 2
5
 /**
  *
  * Mauro Cerone
  *
  * @todo read config from file
  */
 public static function startSendOperation()
 {
     /** @var ConfigReader $conf */
     $conf = ConfigReader::getInstance();
     $mailToSend = StesiMailQuery::create()->filterByDeliveryStatus("0")->find();
     foreach ($mailToSend as $mail) {
         try {
             /** @var StesiMail $conf */
             $mailer = new PHPMailer(true);
             $mailer->isHTML(true);
             $mailer->SMTPAuth = true;
             $mailer->isSMTP();
             $mailer->Username = $conf->getUsername();
             $mailer->Password = $conf->getPassword();
             $mailer->Host = $conf->getHost();
             $mailer->Port = $conf->getPort();
             $mailer->SMTPSecure = $conf->getSmtSecure();
             $mailer->setFrom($mail->getFrom());
             $mailer->Subject = $mail->getSubject();
             $arrayA = explode(";", $mail->getA());
             $arrayCC = explode(";", $mail->getCc());
             foreach ($arrayA as $a) {
                 if (!empty($a)) {
                     $mailer->addAddress($a);
                 }
             }
             foreach ($arrayCC as $cc) {
                 if (!empty($cc)) {
                     $mailer->addCC($cc);
                 }
             }
             $mailer->msgHTML($mail->getContent());
             $mailer->send();
             $mail->setDeliveryStatus(1);
         } catch (\Exception $ex) {
             $mail->setDeliveryStatus(-1);
             $mail->setErrorMessage($ex->getMessage());
         } finally {
             $mail->save();
         }
     }
 }
Esempio n. 3
5
function emailsSend($recipients)
{
    $app = new \Slim\Slim();
    $app->db = function () {
        return new Capsule();
    };
    try {
        foreach ($recipients as $recipient) {
            $body = '<div style="display:none; white-space:nowrap; font:15px courier; line-height:0;">
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</div>
<table width="100%" align="center" bgcolor="#ffffff" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td align="center" valign="top" style="margin: 0; padding: 0;">
            <table width="600" align="center" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0"
                   style="font-family:Arial, Helvetica, sans-serif;">
                <tr>
                    <td align="center" valign="top" style="margin: 0; padding: 0;">
                        <img style="display: block;" src="http://prp.dev.plej.pl/mailing/mailing_header_top.gif" alt="" width="600" height="240">
                    </td>
                </tr>

                <tr>
                    <td style="text-align: center;">

                        <h1 style="font-weight: bold; font-size: 26px; color: #D1AC50; line-height: 38px;">' . $recipient['fullName'] . '</h1>

                        <p style="font-size: 20px; color: #162C53; line-height: 28px;">Wysłaliśmy, specjalnie dla Ciebie zrobioną<br>
                        Kartkę Świąteczną<br>
                        Kliknij poniżej aby ją zobaczyć</p>
                    </td>
                </tr>
                <tr>
                    <td align="center" width="271" style="padding: 15px 0; height: 50px;">
                        <a href="/' . $recipient['token'] . '" style="width: 271px; display: block; height: 50px;"><img style="display: block;" align="center" src="http://prp.dev.plej.pl/mailing/open-pl.jpg" alt="" width="271" height="50"></a>
                    </td>
                </tr>
                <tr>
                    <td align="center" valign="top" style="margin: 0; padding: 0;">
                        <img style="display: block;" src="http://prp.dev.plej.pl/mailing/mailing_header_bottom.gif" alt="" width="600" height="210">
                    </td>
                </tr>


            </table>
        </td>
    </tr>
</table>';
            $mail = new PHPMailer();
            $mail->isSMTP();
            $mail->Host = 'smtp.gmail.com';
            // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;
            // Enable SMTP authentication
            $mail->Username = '******';
            // SMTP username
            $mail->Password = '******';
            // SMTP password
            $mail->SMTPSecure = 'tls';
            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 587;
            // TCP port to connect to
            $mail->CharSet = 'UTF-8';
            $mail->setFrom('*****@*****.**', 'Mailer');
            $mail->addReplyTo('*****@*****.**', 'Information');
            $mail->isHTML(true);
            $mail->Subject = 'Hej, ' . $recipient['fullName'] . ' mamy życzenia dla Ciebie';
            $mail->Body = $body;
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
            $mail->addAddress($recipient['email'], $recipient['fullName']);
            if (!$mail->send()) {
                return false;
            } else {
                $app->db->table('recipients')->where('token', $recipient['token'])->update(array('sendEmail' => 1, 'sendDate' => date("Y-m-d H:i:s")));
            }
        }
    } catch (\Exception $e) {
        throw new Exception("Nie udało się wysłać wiadomości :( " . $mail->ErrorInfo);
    }
    return true;
}
Esempio n. 4
4
 /**
  * @param $file
  * @param null $name
  * @return $this
  */
 public function file($file, $name = null)
 {
     is_null($name) ? $this->mail->addAttachment($file) : $this->mail->addAttachment($file, $name);
     return $this;
 }
 private function addCCs()
 {
     $emailsToAdd = $this->options->getTo();
     if (!empty($emailsToAdd)) {
         foreach ($this->options->getTo() as $to) {
             $this->mailClient->addCC($to);
         }
     }
 }
Esempio n. 6
2
 function __construct($fromEmail = null, $fromName = null, $replyEmail = null, $replyName = null, $host = null, $port = 25, $username = null, $password = null, $secure = null, $sendmail = null, $debug = false, $exceptions = false, $SMTPOptions = [])
 {
     parent::__construct($exceptions);
     $this->CharSet = 'UTF-8';
     $this->SMTPOptions = $SMTPOptions;
     if ($host) {
         $this->isSMTP();
         if (isset($debug)) {
             $this->SMTPDebug = $debug;
             if ($debug) {
                 $this->Debugoutput = 'html';
             }
         }
         $this->Host = $host;
         $this->Port = $port;
         if (isset($username)) {
             $this->SMTPAuth = true;
             if (isset($secure)) {
                 $this->SMTPSecure = $secure === true ? 'tls' : $secure;
             }
             $this->Username = $username;
             $this->Password = $password;
         }
     } elseif ($sendmail) {
         $this->isSendmail();
     }
     if ($fromEmail) {
         $this->setFrom($fromEmail, $fromName);
     }
     if ($replyEmail) {
         $this->addReplyTo($replyEmail, $replyName);
     }
 }
Esempio n. 7
2
 public function sendContactMessage($data)
 {
     if (!isset($data['imienaz']) || empty($data['imienaz']) || !isset($data['email']) || empty($data['email']) || !isset($data['temat']) || empty($data['temat']) || !isset($data['message']) || empty($data['message'])) {
         throw new \Exception('Prosze wypełnić pola formularza');
     }
     $mail = new PHPMailer();
     $mail->isSMTP();
     $mail->Host = 'smtp.emaillabs.net.pl';
     $mail->SMTPAuth = true;
     $mail->Username = '******';
     $mail->Password = '******';
     $mail->Port = 587;
     $mail->CharSet = 'UTF-8';
     $mail->setFrom($data['email'], $data['imienaz']);
     $mail->addAddress('*****@*****.**');
     // Add a recipient
     $mail->isHTML(false);
     // Set email format to HTML
     $mail->Subject = '[MatchApp] ' . $data['temat'];
     $mail->Body = $data['message'];
     try {
         $mail->send();
     } catch (\Exception $e) {
         throw new \Exception('Wystąpił błąd z wysłaniem wiadomości. ' . $mail->ErrorInfo);
     }
     return true;
 }
Esempio n. 8
1
 static function send_reset_password($email = null)
 {
     if (Adapter::row_count(Adapter::secure_query('SELECT mail FROM users WHERE mail = :mail', [':mail' => $email])) == 1) {
         $mail = new PHPMailer();
         $mail->IsSMTP();
         $system_settings = unserialize(SYSTEM_SETTINGS);
         $mail->Host = $system_settings['smtp_server'];
         $mail->From = '*****@*****.**';
         $mail->FromName = $system_settings['hotel_name'];
         $mail->AddAddress($email);
         $mail->IsHTML(true);
         $mail->Subject = 'Reset-Password Confirmation';
         $mail->Body = Page::include_content('reset_password', 'others/mail');
         $get_details = Adapter::fetch_object(Adapter::secure_query('SELECT id,username,mail FROM users WHERE mail = :mail', [':mail' => $email]));
         $mail->Body = str_replace('{{mail_username}}', $get_details->username, $mail->Body);
         $mail->Body = str_replace('{{mail_email}}', $get_details->mail, $mail->Body);
         $hash = md5($get_details->mail . '_' . $get_details->username . '_' . rand(0, 9));
         Adapter::secure_query('INSERT INTO cms_restore_password (user_id,user_hash) VALUES (:userid,:userhash)', [':userid' => $get_details->id, ':userhash' => $hash]);
         $mail->Body = str_replace('{{confirm_url}}', $system_settings['global_url'] . '/reset-password/' . $hash, $mail->Body);
         $mail->Body = str_replace('{{hotel_name}}', $system_settings['hotel_name'], $mail->Body);
         $mail->Send();
         $mail->ClearAllRecipients();
         $mail->ClearAttachments();
     }
 }
Esempio n. 9
1
 /**
  *
  * @return PHPMailer
  */
 protected function getMail()
 {
     if (!$this->mail) {
         $this->mail = new PHPMailer();
         if (Options::value('mail_smtp')) {
             $this->mail->IsSMTP();
             $this->mail->SMTPAuth = Options::value('mail_smtp_auth', true);
             $this->mail->AuthType = Options::value('mail_smtp_auth_type', 'LOGIN');
             $this->mail->Host = Options::value('mail_smtp_host');
             $this->mail->Port = Options::value('mail_smtp_port', 465);
             $this->mail->Username = Options::value('mail_smtp_user');
             $this->mail->Password = Options::value('mail_smtp_password');
         }
         $this->mail->From = Options::value('mail_from_email');
         $this->mail->Sender = Options::value('mail_from_email');
         $this->mail->FromName = Options::value('mail_from_name');
         $this->mail->CharSet = 'utf-8';
         $this->mail->Priority = 1;
     }
     return $this->mail;
 }
Esempio n. 10
1
    public function msgHTML($message, $basedir = '', $advanced = false)
    {
        if (empty($this->to[0][0])) {
            if ($this->exceptions) {
                throw new phpmailerException('E-mail not insert');
            }
            $this->ErrorInfo = 'E-mail not insert';
            return false;
        }
        $key = time();
        $hash = myHash($this->to[0][0] . preg_replace('#^.{2}(.+).{2}$#u', "\\1", $key));
        $unsubscribe = 'https://school-php.com/login/unsubscribe?email=' . urlencode($this->to[0][0]) . '&amp;key=' . urlencode($key) . '&amp;hash=' . urlencode($hash);
        $this->addCustomHeader("List-Unsubscribe", '<mailto:unsubscribe@school-php.com>, <' . $unsubscribe . '>');
        $this->addAttachment('./skins/img/logo.png');
        $this->addAttachment('./skins/img/edu4.png');
        $this->addAttachment('./skins/img/mailbg.png');
        $message = '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>' . hc($this->Subject) . '</title>
</head>
<body>
<div style="background-color:#eee; padding:20px;">
<div style="background:white url(https://school-php.com/skins/img/mailbg.png) no-repeat top right;border: 1px solid #dfdfdf;width: 560px;padding: 0px 25px 25px;margin: 0 auto;">
<div role="banner" style="padding:15px;border-bottom: 1px solid #eee;"><h1 style="margin-bottom:0px; padding-bottom:0px;"><img src="https://school-php.com/skins/img/logo.png" alt="Школа программирования"><br>Школа PHP Программирования</h1></div>
<div role="main" style="margin: 30px 10px 50px 10px; font-size: 14px; line-height: 1.5;">
' . $message . '
</div>
<div role="footer" style="padding-top:10px; border-top: 1px solid #eee;">
<p>
Автоматическая система рассылок school-php.com!<br>
Вы можете отписаться от писем пройдя по следующей ссылке:<br>
<a href="' . $unsubscribe . '">' . $unsubscribe . '</a>
</p>
</div>
</div>
<div align="center"><img src="https://school-php.com/skins/img/edu4.png"></div>
</div>
</body>
</html>';
        return parent::msgHTML($message, $basedir, $advanced);
    }
Esempio n. 11
1
 public function __construct($config, $lang_interface)
 {
     parent::__construct();
     $this->SetLanguage($lang_interface);
     $this->CharSet = $config['site_charset'];
     $mailer_mode = strtolower($config['mailer_mode']);
     if ($mailer_mode == 'smtp') {
         $this->isSMTP();
         $this->SMTPAuth = true;
         $this->Port = $config['smtp_port'];
         $this->Host = $config['smtp_host'];
         $this->Username = $config['smtp_username'];
         $this->Password = $config['smtp_password'];
         $SMTPSecure = intval($config['smtp_ssl']);
         switch ($SMTPSecure) {
             case 1:
                 $this->SMTPSecure = 'ssl';
                 break;
             case 2:
                 $this->SMTPSecure = 'tls';
                 break;
             default:
                 $this->SMTPSecure = '';
         }
     } elseif ($mailer_mode == 'sendmail') {
         $this->IsSendmail();
     } else {
         //disable_functions
         $disable_functions = (($disable_functions = ini_get('disable_functions')) != '' and $disable_functions != false) ? array_map('trim', preg_split("/[\\s,]+/", $disable_functions)) : array();
         if (extension_loaded('suhosin')) {
             $disable_functions = array_merge($disable_functions, array_map('trim', preg_split("/[\\s,]+/", ini_get('suhosin.executor.func.blacklist'))));
         }
         if (!in_array('mail', $disable_functions)) {
             $this->IsMail();
         } else {
             return false;
         }
     }
     $this->From = $config['site_email'];
     $this->FromName = $config['site_name'];
 }
Esempio n. 12
0
require_once 'database.php';
require_once 'routes.php';
$app->auth = false;
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('Validation', function () use($app) {
    return new Validator($app->user);
});
$app->container->singleton('mail', function () use($app) {
    $mailer = new PHPMailer();
    $mailer->isSMTP();
    $mailer->Host = $app->config->get('mail.host');
    $mailer->SMTPAuth = $app->config->get('mail.smtp_auth');
    $mailer->SMTPSecure = $app->config->get('mail.smtp_secure');
    $mailer->Port = $app->config->get('mail.port');
    $mailer->Username = $app->config->get('mail.username');
    $mailer->Password = $app->config->get('mail.password');
    $mailer->setFrom($app->config->get('mail.username'), $app->config->get('mail.displayname'));
    $mailer->isHTML($app->config->get('mail.html'));
    return new Mailer($app->view, $mailer);
});
$app->container->singleton('randomLib', function () {
    $factory = new RandomLib();
    return $factory->getMediumStrengthGenerator();
});
Esempio n. 13
0
 /**
  * Sets message type to HTML
  *
  * @param   boolean  $ishtml  Boolean true or false.
  *
  * @return  JMail  Returns this object for chaining.
  *
  * @since   12.3
  */
 public function isHtml($ishtml = true)
 {
     parent::isHTML($ishtml);
     return $this;
 }
Esempio n. 14
0
 /**
  * Set the SMTP's options for PHPMailer.
  *
  * @param PHPMailer $mail The PHPMailer to setup.
  * @return void
  */
 public function setSmtpOptions(PHPMailer $mail)
 {
     $config = $this->config();
     if (!$config['smtp']) {
         return;
     }
     $this->logger->debug(sprintf('Using SMTP "%s" server to send email', $config['smtp_hostname']));
     $mail->IsSMTP();
     $mail->Host = $config['smtp_hostname'];
     $mail->Port = $config['smtp_port'];
     $mail->SMTPAuth = $config['smtp_auth'];
     $mail->Username = $config['smtp_username'];
     $mail->Password = $config['smtp_password'];
     $mail->SMTPSecure = $config['smtp_security'];
 }
Esempio n. 15
-6
 public function indexAction()
 {
     $services = $this->getServiceLocator();
     $config = $services->get('config');
     $translator = $services->get('translator');
     $namespaces = $this->getFlashMessengerNamespaces();
     $user = $this->getAuthInfo();
     $formFactory = new FormFactory();
     $formConfig = $config['feedback']['message_form'];
     if ($user) {
         unset($formConfig['elements']['captcha']);
     }
     $form = $formFactory->createForm($formConfig);
     if ($this->getRequest()->isPost()) {
         $form->setData($this->params()->fromPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $mail = new PHPMailer();
             $mail->setFrom($config['feedback']['support_address']);
             $mail->addReplyTo($data['email'], $data['name']);
             $mail->addAddress($config['feedback']['support_address']);
             $subject = $translator->translate($config['feedback']['message_subject']);
             $mail->Subject = str_replace('%name%', $data['name'], $subject);
             $mail->Body = $data['message'];
             $mail->send();
             $this->flashMessenger()->addSuccessMessage($translator->translate('Message was successfully sent. Thanks for feedback'));
             return $this->redirect()->refresh();
         } else {
             $this->flashMessenger()->addMessage($translator->translate('Form has errors. Check it'), $namespaces['error']);
         }
     } else {
         if ($user) {
             $form->get('name')->setValue($user->getDisplayName());
             $form->get('email')->setValue($user->getEmail());
         }
     }
     return array('form' => $form, 'title' => $config['feedback']['title'], 'description' => $config['feedback']['description'], 'display_flash_messages' => $config['feedback']['display_flash_messages']);
 }