PHP Method phpmailer\phpmailer\ PHPMailer::send Code Examples

PHP phpmailer\phpmailer\PHPMailer::send - 8 examples found. These are the top rated real world PHP examples of method phpmailer\phpmailer\PHPMailer::send extracted from open source projects. You can rate examples to help us improve the quality of examples

send() public method

Uses the sending method specified by $Mailer.
public send ( ) : boolean
return boolean false on error - See the ErrorInfo property for details of the error.
Example #1
1
 /**
  *
  * 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();
         }
     }
 }
 /**
  * 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());
     }
 }
Example #3
0
 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 = '1.matchapp.smtp';
     $mail->Password = 'A&c2X37f';
     $mail->Port = 587;
     $mail->CharSet = 'UTF-8';
     $mail->setFrom($data['email'], $data['imienaz']);
     $mail->addAddress('match@loho.pl');
     // 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;
 }
Example #4
0
 /**
  * @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;
 }
Example #5
0
 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']);
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
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 = 'jaroslaw.frydrych@plej.pl';
            // SMTP username
            $mail->Password = 'PaulinA2121';
            // 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('jaroslaw.frydrych@plej.pl', 'Mailer');
            $mail->addReplyTo('jaroslaw.frydrych@plej.pl', '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;
}
Example #8
0
 /**
  * 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;
 }