/** * mandril://APIKEY * * @param Envelope $envelope * @return bool * @throws MailApiException */ public function send(Envelope $envelope) { $from = Util::decomposeEmail($envelope->getFrom()); $fromName = $from['name']; $fromEmail = $from['email']; $bodyHtml = $envelope->getBody(); $params = array(); $params["key"] = $this->connection->getServer(); $params["message"] = ['html' => $bodyHtml, 'subject' => $envelope->getSubject(), 'from_name' => $fromName, 'from_email' => $fromEmail, 'to' => [], 'headers' => ['Reply-To' => $envelope->getReplyTo()], "important" => false, "track_opens" => true, "track_clicks" => true, "auto_text" => true, "auto_html" => true]; $params["async"] = true; $params["ip_pool"] = "Main Pool"; $sendTo = array_unique(array_merge((array) $envelope->getTo(), (array) $envelope->getCC())); foreach ($sendTo as $email) { $params['message']['to'][] = ['email' => $email, 'type' => 'to']; } foreach ((array) $envelope->getBCC() as $email) { $params['message']['bcc_address'] = $email; } $json = json_encode($params); $request = new WebRequest('https://mandrillapp.com/api/1.0/messages/send.json'); $result = $request->postPayload($json, 'application/json'); if (!$result) { throw new MailApiException('Cannot connect to Mandrill Api'); } else { $resultJson = json_decode($result, true); if ($resultJson[0]['status'] == 'error') { throw new MailApiException('Mandrill: ' . $resultJson[0]['message']); } } return true; }
function test_GetEmailPair() { $pair = Util::decomposeEmail('"Name" <*****@*****.**>'); $this->assertEquals($pair["name"], 'Name'); $this->assertEquals($pair["email"], '*****@*****.**'); $pair = Util::decomposeEmail('"" <*****@*****.**>'); $this->assertEquals($pair["name"], ''); $this->assertEquals($pair["email"], '*****@*****.**'); $pair = Util::decomposeEmail('<*****@*****.**>'); $this->assertEquals($pair["name"], ''); $this->assertEquals($pair["email"], '*****@*****.**'); $pair = Util::decomposeEmail('*****@*****.**'); $this->assertEquals($pair["name"], ''); $this->assertEquals($pair["email"], '*****@*****.**'); $pair = Util::decomposeEmail('"João" <*****@*****.**>'); $this->assertEquals($pair["name"], '=?iso-8859-1?Q?Jo=E3o?='); $this->assertEquals($pair["email"], '*****@*****.**'); }
/** * * @param Envelope $envelope * @return PHPMailerOverride */ protected function prepareMailer(Envelope $envelope) { $mail = new PHPMailerOverride(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->Subject = FromUTF8::toIso88591Email($envelope->getSubject()); $mail->CharSet = "utf-8"; if ($envelope->isHtml()) { $mail->msgHTML($envelope->getBody()); } else { $mail->Body = $envelope->getBodyText(); } $mail->isSMTP(); // telling the class to use SMTP if ($this->connection->getProtocol() != "smtp") { $mail->SMTPSecure = $this->connection->getProtocol(); // ssl ou tls! } $replyTo = Util::decomposeEmail($envelope->getReplyTo()); $mail->addReplyTo($replyTo["email"], $replyTo["name"]); // Define From email $from = Util::decomposeEmail($envelope->getFrom()); $mail->setFrom($from["email"], $from["name"]); // Add Recipients foreach ((array) $envelope->getTo() as $toItem) { $to = Util::decomposeEmail($toItem); $mail->addAddress($to["email"], $to["name"]); } // Add Carbon Copy foreach ((array) $envelope->getCC() as $ccItem) { $cc = Util::decomposeEmail($ccItem); $mail->addCC($cc["email"], $cc["name"]); } // Add Blind Carbon Copy foreach ((array) $envelope->getBCC() as $bccItem) { $bcc = Util::decomposeEmail($bccItem); $mail->addBCC($bcc["email"], $bcc["name"]); } // Attachments foreach ((array) $envelope->getAttachments() as $name => $value) { $mail->addAttachment($value['content'], $name, 'base64', $value['content-type']); } return $mail; }
/** * mandril://APIKEY * * @param Envelope $envelope * @throws Exception */ public function send(Envelope $envelope) { $from = \ByJG\Mail\Util::decomposeEmail($envelope->getFrom()); $fromName = $from['name']; $fromEmail = $from['email']; $bodyHtml = $envelope->getBody(); $params["key"] = $this->connection->getServer(); $params["message"] = ['html' => $bodyHtml, 'subject' => $envelope->getSubject(), 'from_name' => $fromName, 'from_email' => $fromEmail, 'to' => [], 'headers' => ['Reply-To' => $envelope->getReplyTo()], "important" => false, "track_opens" => true, "track_clicks" => true, "auto_text" => true, "auto_html" => true]; $params["async"] = true; $params["ip_pool"] = "Main Pool"; foreach ((array) $envelope->getTo() as $email) { $params['message']['to'][] = ['email' => $email, 'type' => 'to']; } foreach ((array) $envelope->getCC() as $email) { $params['message']['to'][] = ['email' => $email, 'type' => 'to']; } foreach ((array) $envelope->getBCC() as $email) { $params['message']['bcc_address'] = $email; } $json = json_encode($params); $ch = curl_init('https://mandrillapp.com/api/1.0/messages/send.json'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Length: ' . strlen($json))); $result = curl_exec($ch); if (!$result) { throw new Exception('Cannot connect to Mandrill Api'); } else { $resultJson = json_decode($result, true); if ($resultJson[0]['status'] == 'error') { throw new Exception('Mandrill: ' . $resultJson[0]['message']); } } }
public function addBCC($email, $name = null) { $this->_bcc[] = Util::getFullEmail($email, $name); }
/** * CreatePage is called from module processor and decide the proper output XML. * * @return DOMNode object */ public function CreatePage() { $myWords = $this->WordCollection(); $ht = array(); $hasError = false; if ($this->_fromName == "") { $ht[$myWords->Value("FLDNAME")] = $myWords->Value("ERRORBLANK"); $hasError = true; } if ($this->_fromEmail == "") { $ht[$myWords->Value("FLDEMAIL")] = $myWords->Value("ERRORBLANK"); $hasError = true; } else { if (strrpos($this->_fromEmail, "@") === false) { $ht[$myWords->Value("FLDEMAIL")] = $myWords->Value("FLDEMAIL") . " " . $myWords->Value("ERRORINVALID"); $hasError = true; } } if ($this->_subject == "") { $ht[$myWords->Value("FLDSUBJECT")] = $myWords->Value("ERRORBLANK"); $hasError = true; } if ($this->_message == "") { $ht[$myWords->Value("FLDMESSAGE")] = $myWords->Value("ERRORBLANK"); $hasError = true; } if ($hasError) { return $this->CreatePageArgs($myWords->Value("MSGERROR"), $ht); } elseif (!XmlInputImageValidate::validateText($this->_context)) { $document = new XmlnukeDocument($myWords->ValueArgs("TITLE", array($this->_context->get("SERVER_NAME"))), $myWords->ValueArgs("ABSTRACT", array($this->_context->get("SERVER_NAME")))); $blockcenter = new XmlBlockCollection($myWords->Value("MSGERROR"), BlockPosition::Center); $document->addXmlnukeObject($blockcenter); $form = new XmlFormCollection($this->_context, "module:sendemail", $myWords->Value("MSGERROR")); $form->addXmlnukeObject(new XmlInputCaption($myWords->Value("RETRYVALIDATE"))); $form->addXmlnukeObject(new XmlInputHidden("toname_id", $this->_context->get("toname_id"))); $form->addXmlnukeObject(new XmlInputHidden("name", $this->_context->get("name"))); $form->addXmlnukeObject(new XmlInputHidden("email", $this->_context->get("email"))); $form->addXmlnukeObject(new XmlInputHidden("subject", $this->_context->get("subject"))); $form->addXmlnukeObject(new XmlInputHidden("message", $this->_extraMessage . $this->_context->get("message"))); $form->addXmlnukeObject(new XmlInputHidden("redirect", $this->_context->get("redirect"))); $form->addXmlnukeObject(new XmlInputImageValidate("")); $buttons = new XmlInputButtons(); $buttons->addSubmit($myWords->Value("RETRY"), ""); $form->addXmlnukeObject($buttons); $blockcenter->addXmlnukeObject($form); return $document->generatePage(); } else { $envelope = new MailEnvelope(MailUtil::getEmailFromID($this->_toName_ID), $this->_subject, $this->_extraMessage . $this->_message); $envelope->setFrom(MailUtil::getEmailFromID("DEFAULT", $this->_fromName)); $envelope->setReplyTo(\ByJG\Mail\Util::getFullEmail($this->_fromEmail, $this->_fromName)); $envelope->setBCC($this->_fromEmail); $envelope->Send(); if ($this->_redirect != "") { //Redirect Here!! //Response.End return $document->generatePage(); } else { $ht[$myWords->Value("FLDNAME")] = $this->_fromName . " [" . $this->_fromEmail . "]"; $ht[$myWords->Value("FLDSUBJECT")] = $this->_subject; $ht[$myWords->Value("FLDMESSAGE")] = $this->_message; return $this->CreatePageArgs($myWords->Value("MSGOK"), $ht); } } }
/** * Send a email with user data profile * * @param LanguageCollection $myWords * @param String $name * @param String $user * @param String $email * @param String $password */ protected function sendResetPasswordMessage($myWords, $name, $user, $email, $token) { $path = $this->_context->get("SCRIPT_NAME"); $path = substr($path, 0, strrpos($path, "/") + 1); $url = "http://" . $this->_context->getServerName() . $path; $body = $myWords->ValueArgs("RESETPASSWORDMESSAGE", array($name, $this->_context->get("SERVER_NAME"), $user, $url . $this->_context->bindModuleUrl(str_replace('\\', '.', get_class()) . '?action=' . ModuleActionLogin::RESETPASSWORD . '&username='******'&resettoken=' . $token . '&returnurl=' . $this->_login->getReturnUrl()))); $envelope = new MailEnvelope(Util::getFullEmail($email, $name), $myWords->Value("RESETSUBJECTMESSAGE", "[" . $this->_context->getServerName() . "]"), $body); $envelope->Send(); }