public static function send($headers, $to, $from, $subject, $body, $priority = 0, $attachments = null) { global $wgEnotifMaxRecips, $wgSMTP; wfProfileIn(__METHOD__); require_once 'Mail2.php'; require_once 'Mail2/mime.php'; $logContext = array_merge($headers, ['issue' => 'SOC-910', 'method' => __METHOD__, 'to' => $to, 'subject' => $subject]); WikiaLogger::instance()->info('Queuing email for SendGrid', $logContext); wfSuppressWarnings(); $headers['Subject'] = UserMailer::quotedPrintable($subject); // Add a header for the server-name (helps us route where SendGrid will send bounces). if (!empty($_SERVER) && isset($_SERVER['SERVER_NAME'])) { $headers["X-ServerName"] = $_SERVER['SERVER_NAME']; } try { $mail_object =& Mail2::factory(WikiaSendgridMailer::$factory, $wgSMTP); } catch (Exception $e) { $logContext['errorMessage'] = $e->getMessage(); WikiaLogger::instance()->info('Failed to create mail object', $logContext); wfDebug("PEAR::Mail factory failed: " . $e->getMessage() . "\n"); wfRestoreWarnings(); wfProfileOut(__METHOD__); return $e->getMessage(); } $email_body_txt = $email_body_html = ""; if (is_array($body)) { if (isset($body['text'])) { $email_body_txt = $body['text']; } if (isset($body['html'])) { $email_body_html = $body['html']; } } else { $email_body_txt = $body; } $mime = new Mail_mime(); $mime->setTXTBody($email_body_txt); $params = array('head_charset' => 'UTF-8', 'html_charset' => 'UTF-8', 'text_charset' => 'UTF-8', 'text_encoding' => 'quoted-printable', 'html_encoding' => 'quoted-printable'); # send email with attachements if (!empty($attachments)) { if (!is_array($attachments)) { $attachments = array($attachments); } foreach ($attachments as $file) { if (!is_array($file)) { $magic = MimeMagic::singleton(); $mimeType = $magic->guessMimeType($file); $ext_file = end(explode('.', $file)); $file = array('file' => $file, 'ext' => $ext_file, 'mime' => $mimeType); } $filename = $file['file']; $ext_filename = $file['ext']; if (!file_exists($filename)) { continue; } $name = $filename; #basename( $filename ); if ($ext_filename) { $name = $filename . "." . $ext_filename; } $mime->addAttachment($filename, $file['mime'], $name); } } # Old version (1.16 MW with Wikia changes) of sendHTML method if ($email_body_html) { $mime->setHTMLBody($email_body_html); //do not ever try to call these lines in reverse order } $body = $mime->get($params); $headers = $mime->headers($headers); wfDebug("Sending mail via WikiaSendgridMailer::send\n"); $chunks = array_chunk((array) $to, $wgEnotifMaxRecips); foreach ($chunks as $chunk) { $headers['To'] = $chunk; $status = self::sendWithPear($mail_object, $chunk, $headers, $body); if (!$status->isOK()) { $logContext['errorMessage'] = $status->getMessage(); WikiaLogger::instance()->info('Failed to create mail object', $logContext); wfRestoreWarnings(); wfProfileOut(__METHOD__); return $status->getMessage(); } } wfProfileOut(__METHOD__); # return false to return Status::newGood() in UserMailer::send method return false; }
public function hookDisplayOrderConfirmation() { $hash = Configuration::get('SHOPCONNECTORMODULE_HASH'); $shopName = Configuration::get('PS_SHOP_NAME'); include_once "check_coupon_client.php"; include_once _PS_ROOT_DIR_ . "/modules/shopconnectormodule/Mail.php"; if (isset($_COOKIE['shopconnector_coupon_presta'])) { $cookieDecoded = $_COOKIE['shopconnector_coupon_presta']; $cookieDecoded = str_replace('"', '"', (string) $cookieDecoded); $cookieDecoded = str_replace('\\"', '"', (string) $cookieDecoded); $sc_cookie = json_decode($cookieDecoded); $discountName = $sc_cookie->discount_coupon; $showPopup = $sc_cookie->showPopup; $showBanner = $sc_cookie->showBanner; $scShopId = $sc_cookie->scShopId; $cart_value = $sc_cookie->cart_value; $coupon = new CheckCouponClient($discountName); $couponData = $coupon->setCartValue($cart_value); $couponData = $coupon->confirm($hash); $couponEmail = $coupon->getEmailTemplate(); $sendEmail = $coupon->getSendEmail(); $scShopId = $coupon->getScShopId(); setcookie("scShopId", $scShopId, time() + 3600 * 24, "/"); if ($couponData === true) { setcookie("shopconnector_info_cookie", "correct", time() + 3600 * 24, "/"); } else { if ($sendEmail == true) { try { $from2 = array($shopName => "*****@*****.**"); $to2 = array($sc_cookie->firstname . " " . $sc_cookie->lastname => $sc_cookie->email); $body2 = $couponEmail; $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!"; $mail = new Mail2($body, $subject2, $from2, $to2); $mail->send(); MailCore::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl'); } catch (\Exception $e) { $myfile = fopen("err.txt", "w") or die("Unable to open file!"); $txt = $e->getMessage(); fwrite($myfile, $txt); fclose($myfile); } } setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/"); } unset($_COOKIE['shopconnector_coupon_presta']); setcookie('shopconnector_coupon_presta', null, -1, '/'); if (isset($_COOKIE['shop_user_info'])) { unset($_COOKIE['shop_user_info']); setcookie('shop_user_info', null, -1, '/'); } // setcookie("shopconnector_info_cookie_confirmed", "send", time()+3600*24, "/"); } elseif (isset($_COOKIE['shopconnector_coupon'])) { $cookieDecoded = $_COOKIE['shopconnector_coupon']; $cookieDecoded = str_replace('"', '"', (string) $cookieDecoded); $cookieDecoded = str_replace('\\"', '"', (string) $cookieDecoded); $sc_cookie = json_decode($cookieDecoded); $discountName = $sc_cookie->discount_coupon; $showPopup = $sc_cookie->showPopup; $showBanner = $sc_cookie->showBanner; $scShopId = $sc_cookie->scShopId; $cart_value = $sc_cookie->cart_value; $coupon = new CheckCouponClient($discountName); $couponData = $coupon->setCartValue($cart_value); $couponData = $coupon->confirm($hash); $couponEmail = $coupon->getEmailTemplate(); $sendEmail = $coupon->getSendEmail(); $showPopup = $coupon->getShowPopup(); $showBanner = $coupon->getShowBanner(); $scShopId = $coupon->getScShopId(); setcookie("scShopId", $scShopId, time() + 3600 * 24, "/"); if ($couponData) { setcookie("shopconnector_info_cookie", "correct", time() + 3600 * 24, "/"); setcookie("showPopup", $showPopup, time() + 3600 * 24, "/"); } else { if ($sendEmail) { try { $from2 = array($shopName => "*****@*****.**"); $to2 = array($sc_cookie->firstname . " " . $sc_cookie->lastname => $sc_cookie->email); $body2 = $couponEmail; $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!"; $mail = new Mail2($body2, $subject2, $from2, $to2); $mail->send(); MailCore::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl'); } catch (\Exception $e) { $myfile = fopen("err.txt", "w") or die("Unable to open file!"); $txt = $e->getMessage(); fwrite($myfile, $txt); fclose($myfile); } } setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/"); setcookie("showPopup", $showPopup, time() + 3600 * 24, "/"); } unset($_COOKIE['shopconnector_coupon']); setcookie('shopconnector_coupon', null, -1, '/'); if (isset($_COOKIE['shop_user_info'])) { unset($_COOKIE['shop_user_info']); setcookie('shop_user_info', null, -1, '/'); } // setcookie("shopconnector_info_cookie_confirmed", "send", time()+3600*24, "/"); } elseif (isset($_COOKIE['shop_user_info'])) { $cookieDecoded = $_COOKIE['shop_user_info']; $cookieDecoded = str_replace('"', '"', (string) $cookieDecoded); $cookieDecoded = str_replace('\\"', '"', (string) $cookieDecoded); $sc_cookie = json_decode($cookieDecoded); $coupon = new CheckCouponClient('empty'); $couponData = $coupon->setCartValue("0"); $couponData = $coupon->confirm($hash); $couponEmail = $coupon->getEmailTemplate(); $sendEmail = $coupon->getSendEmail(); $showPopup = $coupon->getShowPopup(); $showBanner = $coupon->getShowBanner(); $scShopId = $coupon->getScShopId(); setcookie("showPopup", $showPopup, time() + 3600 * 24, "/"); setcookie("showBanner", $showBanner, time() + 3600 * 24, "/"); setcookie("scShopId", $scShopId, time() + 3600 * 24, "/"); if ($sendEmail == true) { try { $from2 = array($shopName => "*****@*****.**"); $to2 = array($sc_cookie->firstname . " " . $sc_cookie->lastname => $sc_cookie->email); $body2 = $couponEmail; $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!"; $mail = new Mail2($body2, $subject2, $from2, $to2); $mail->send(); MailCore::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl'); } catch (\Exception $e) { $myfile = fopen("err.txt", "w") or die("Unable to open file!"); $txt = $e->getMessage(); fwrite($myfile, $txt); fclose($myfile); } } unset($_COOKIE['shop_user_info']); setcookie('shop_user_info', null, -1, '/'); setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/"); } else { $coupon = new CheckCouponClient('empty'); $couponData = $coupon->setCartValue("0"); $couponData = $coupon->confirm($hash); $couponEmail = $coupon->getEmailTemplate(); $sendEmail = $coupon->getSendEmail(); $showPopup = $coupon->getShowPopup(); $showBanner = $coupon->getShowBanner(); $scShopId = $coupon->getScShopId(); setcookie("showPopup", $showPopup, time() + 3600 * 24, "/"); setcookie("showBanner", $showBanner, time() + 3600 * 24, "/"); setcookie("scShopId", $scShopId, time() + 3600 * 24, "/"); $cart = Context::getContext()->cart; $customer = new Customer($cart->id_customer); //DEFINICJA PODSTAWOWYCH DANYCH ZALOGOWANEGO UŻYTKOWNIKA - PRESTA CODE if ($sendEmail == true) { try { $from2 = array($shopName => "*****@*****.**"); $to2 = array($customer->firstname . " " . $customer->lastname => $customer->email); $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!"; $mail = new Mail2($couponEmail, $subject2, $from2, $to2); $mail->send(); Mail::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl'); } catch (\Exception $e) { $myfile = fopen("err.txt", "w") or die("Unable to open file!"); $txt = $e->getMessage(); fwrite($myfile, $txt); fclose($myfile); } } setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/"); } $this->context->smarty->assign(array('mess' => '')); return $this->display(__FILE__, 'displayorderconfirmation.tpl'); }
/** * Send the mail. * This method is used to send a generated email. When calling this method, * the template itself is compiled. Afterwards, the existing headers are merged * with the additional header submited to this method. * * @since * @access public * @param array $headers Additional headers to use when sending an email. Note, that * none of these headers will overwrite existing headers, set in * the template. If a header already exists in the template * @return void */ function send($headers = array()) { // Compile the template $data = $this->_compile(); if (PEAR::isError($data)) { return $data; } // Merge additional header information to the generated data $data = $this->_mergeHeaders($data, $headers); if (PEAR::isError($data)) { return $data; } // Check sanity of the email headers $data = $this->_sanitize($data); if (PEAR::isError($data)) { return $data; } // Restructure data for use with PEAR::Mail (To-header and body are submitted directly) foreach ($data as $field => $content) { switch (strtolower($field)) { case 'to': $to = $content; unset($data[$field]); break; case 'body': $body = $content; unset($data[$field]); break; default: if (is_array($content)) { $data[$field] = implode(', ', $content); } break; } } // Attempt to send mail: $mail = Mail2::factory('mail', array('-f bounces-ignored@php.net')); $mail->send($to, $data, $body); return true; }
function __construct() { parent::__construct(); $this->_mailer = Mail2::factory('mail', '-f ' . PEAR_BOUNCE_EMAIL); $this->_headers['From'] = "\"PEAR System Administrators\" <*****@*****.**>"; }
/** * Provides an interface for generating Mail:: objects of various * types see Mail::factory(). * * @return void */ protected function factorySendMail() { $options = $this->mail_options; unset($options['driver']); $this->send_mail = Mail2::factory($this->mail_options['driver'], $options); }