isSMTP() public method

Send messages using SMTP.
public isSMTP ( ) : void
return void
 private function setOptions()
 {
     $this->mailClient->isSMTP();
     $this->mailClient->SMTPAuth = true;
     $this->mailClient->SMTPSecure = 'tls';
     // Enable TLS encryption, `ssl` also accepted
     $this->mailClient->addAddress($this->options->getFrom());
     $this->mailClient->Host = $this->options->getHost();
     $this->mailClient->Username = $this->options->getUserName();
     $this->mailClient->Password = $this->options->getPassword();
     $this->mailClient->setFrom($this->options->getFrom());
     $this->mailClient->Port = $this->options->getPort();
     $this->addCCs();
 }
示例#2
6
文件: Auth.php 项目: phpauth/phpauth
 /**
  * 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;
 }
示例#3
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();
         }
     }
 }
示例#4
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;
}
示例#5
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;
 }
示例#6
1
 /**
  *
  */
 private function config()
 {
     if (isset($this->config['lang']['local']) && isset($this->config['lang']['path'])) {
         $this->mail->setLanguage($this->config['lang']['local'], $this->config['lang']['path']);
     }
     $this->mail->CharSet = $this->config['charset'];
     switch ($this->config['transport']) {
         case 'smtp':
             $this->mail->isSMTP();
             if (isset($this->config['debug'])) {
                 $this->mail->SMTPDebug = $this->config['debug'];
                 $this->mail->Debugoutput = 'html';
             }
             $this->mail->Host = $this->config['host'];
             if (isset($this->config['user'])) {
                 $this->mail->SMTPAuth = true;
                 $this->mail->Username = $this->config['user'];
                 $this->mail->Password = $this->config['pass'];
                 $this->mail->Port = $this->config['port'];
                 if (isset($this->config['encrypt'])) {
                     $this->mail->SMTPSecure = $this->config['encrypt'];
                 }
             }
             break;
         case 'sendmail':
             $this->mail->isSendmail();
             $this->mail->Sendmail = $this->config['command'];
             break;
     }
 }
示例#7
0
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();
});
$view = $app->view();