send() 공개 메소드

Uses the sending method specified by $Mailer.
public send ( ) : boolean
리턴 boolean false on error - See the ErrorInfo property for details of the error.
예제 #1
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;
 }
예제 #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();
         }
     }
 }
예제 #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;
}
예제 #4
3
 /**
  * @param null $to
  * @param null $from
  * @param null $subject
  * @param null $content
  * @param null $file
  * @return bool
  */
 public function send($to = null, $from = null, $subject = null, $content = null, $file = null)
 {
     if (is_null($to)) {
         $this->config();
         if ($this->mail->send()) {
             $this->mail = new \PHPMailer\PHPMailer\PHPMailer();
             return true;
         }
         return false;
     } elseif (!is_null($to) && !is_null($from) && !is_null($subject) && !is_null($content)) {
         $this->subject($subject);
         $this->from($from);
         $this->to($to);
         $this->content($content);
         if (!is_null($file)) {
             $this->file($file);
         }
         $this->mail->send();
         $this->mail = new \PHPMailer\PHPMailer\PHPMailer();
         return true;
     }
     return false;
 }
예제 #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
0
파일: mail.php 프로젝트: Rai-Ka/joomla-cms
 /**
  * Send the mail
  *
  * @return  boolean  Boolean true if successful.
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 public function Send()
 {
     if (JFactory::getConfig()->get('mailonline', 1)) {
         if ($this->Mailer == 'mail' && !function_exists('mail')) {
             throw new RuntimeException(JText::_('JLIB_MAIL_FUNCTION_DISABLED'), 500);
         }
         try {
             // Try sending with default settings
             $result = parent::send();
         } catch (phpmailerException $e) {
             $result = false;
             if ($this->SMTPAutoTLS) {
                 /**
                  * PHPMailer has an issue with servers with invalid certificates
                  *
                  * See: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#opportunistic-tls
                  */
                 $this->SMTPAutoTLS = false;
                 try {
                     // Try it again with TLS turned off
                     $result = parent::send();
                 } catch (phpmailerException $e) {
                     // Keep false for B/C compatibility
                     $result = false;
                 }
             }
         }
         if ($result == false) {
             throw new RuntimeException(JText::_($this->ErrorInfo), 500);
         }
         return $result;
     }
     JFactory::getApplication()->enqueueMessage(JText::_('JLIB_MAIL_FUNCTION_OFFLINE'));
     return false;
 }
 /**
  * Sends a report of the working day.
  * @param WorkingDay $day
  * @throws MailProviderException
  * @throws \PHPMailer\PHPMailer\Exception
  */
 public function sendReportOf(WorkingDay $day)
 {
     try {
         $this->renderMail($day);
         $this->mailClient->send();
     } catch (Exception $ex) {
         throw new MailProviderException($ex->errorMessage());
     }
 }
예제 #8
-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']);
 }