/** * Fills in message using blocks from a template (`body`, `subject`, `from`). * If there is no `body` block then whole template will be used. * If there is no `subject` or `from` block then corresponding default value will be used. * @param \Swift_Message $message * @param \Twig_Template $templateContent * @param array $data */ protected function populateMessage(\Swift_Message $message, \Twig_Template $templateContent, $data) { $body = $templateContent->hasBlock('body') ? $templateContent->renderBlock('body', $data) : $templateContent->render($data); $subject = $templateContent->hasBlock('subject') ? $templateContent->renderBlock('subject', $data) : $this->defaultSubject; $from = $templateContent->hasBlock('from') ? $templateContent->renderBlock('from', $data) : $this->defaultFrom; $message->setFrom($from)->setSubject($subject)->setBody($body, 'text/html', 'utf-8'); }
/** * @param string $subject * @param string $body * @param array|string $to * @param array|string $from * @param array|Attachment|null $attachments * @return int */ public function send($subject, $body, $to, $from, $attachments = null) { $this->message->setSubject($subject); $this->message->setFrom($from); $this->message->setTo($to); $this->message->setBody($body, self::BODY_TYPE); $this->processAttachments($attachments); return $this->mailer->send($this->message); }
public function __construct() { $this->registry = Registry::getInstance(); $this->mailerConfig = $this->registry->config->getMailer(); $this->message = \Swift_Message::newInstance(); echo $this->mailerConfig->getSender() . PHP_EOL; $this->message->setFrom($this->mailerConfig->getSender()); $this->transport = \Swift_SmtpTransport::newInstance($this->mailerConfig->getHost(), $this->mailerConfig->getPort(), 'ssl')->setUsername($this->mailerConfig->getUser())->setPassword($this->mailerConfig->getPass()); parent::__construct($this->transport); }
public function __construct($key) { parent::__construct(); $newPassword = uniqid(); $reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword); if ($reset) { $user = ModelUser::getById($reset); if ($user->hasRow()) { // Send mail with new password // TODO: Move this shit to separate html template $user->setEmailConfirmed(true); $user->update(); $text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: "******"\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team"; $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('New password for NinjaImg')); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->setTo($user->username); $swift->send($message); $this->setMessage('A new password has been sent to your e-mail.', 'success'); redirect(url('user.login')); } redirect(url('home')); } }
/** * @param $to * @param $subject * @param $body * @return bool */ public function send($to, $subject, $body) { include_once "vendor/autoload.php"; date_default_timezone_set("Asia/Colombo"); $this->CI->config->load('send_grid'); $username = $this->CI->config->item('send_grid_username'); $password = $this->CI->config->item('send_grid_password'); $smtp_server = $this->CI->config->item('send_grid_smtp_server'); $smtp_server_port = $this->CI->config->item('send_grid_smtp_server_port'); $sending_address = $this->CI->config->item('email_sender_address'); $sending_name = $this->CI->config->item('email_sender_name'); $from = array($sending_address => $sending_name); $to = array($to); $transport = Swift_SmtpTransport::newInstance($smtp_server, $smtp_server_port); $transport->setUsername($username); $transport->setPassword($password); $swift = Swift_Mailer::newInstance($transport); $message = new Swift_Message($subject); $message->setFrom($from); $message->setBody($body, 'text/html'); $message->setTo($to); $message->addPart($body, 'text/plain'); // send message if ($recipients = $swift->send($message, $failures)) { return true; } else { return false; } }
/** * @inheritDoc */ public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null) { if (!$wrappedMessage instanceof MailWrappedMessage) { throw new MailWrapperSetupException('Not MailWrappedMessage'); } $message = new \Swift_Message(); foreach ($wrappedMessage->getToRecipients() as $address) { $message->addTo($address); } foreach ($wrappedMessage->getCcRecipients() as $address) { $message->addCc($address); } foreach ($wrappedMessage->getBccRecipients() as $address) { $message->addBcc($address); } $message->setReplyTo($wrappedMessage->getReplyTo()); $message->setFrom($wrappedMessage->getFrom()); $message->setSubject($wrappedMessage->getSubject()); if ($wrappedMessage->getContentText()) { $message->setBody($wrappedMessage->getContentText()); } if ($wrappedMessage->getContentHtml()) { $message->setBody($wrappedMessage->getContentHtml(), 'text/html'); } return $message; }
public function testSend() { $message = new Swift_Message(); $message->setFrom('*****@*****.**', 'Johnny #5'); $message->setSubject('Is alive!'); $message->addTo('*****@*****.**', 'A. Friend'); $message->addTo('*****@*****.**'); $message->addCc('*****@*****.**'); $message->addCc('*****@*****.**', 'Extra 2'); $message->addBcc('*****@*****.**'); $message->addBcc('*****@*****.**', 'Extra 4'); $message->addPart('<q>Help me Rhonda</q>', 'text/html'); $message->addPart('Doo-wah-ditty.', 'text/plain'); $attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain'); $attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain'); $attachment2->setDisposition('inline'); $message->attach($attachment); $message->attach($attachment2); $message->setPriority(1); $headers = $message->getHeaders(); $headers->addTextHeader('X-PM-Tag', 'movie-quotes'); $messageId = $headers->get('Message-ID')->getId(); $transport = new PostmarkTransportStub('TESTING_SERVER'); $client = $this->getMock('GuzzleHttp\\Client', array('request')); $transport->setHttpClient($client); $o = PHP_OS; $v = phpversion(); $client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <*****@*****.**>', 'To' => '"A. Friend" <*****@*****.**>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <*****@*****.**>', 'Bcc' => 'another+3@example.com,"Extra 4" <*****@*****.**>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]])); $transport->send($message); }
/** * Creates a swift message from a ParsedMessage, handles defaults * * @param ParsedMessage $parsedMessage * * @return \Swift_Message */ protected function transformMessage(ParsedMessage $parsedMessage) { $message = new \Swift_Message(); if ($from = $parsedMessage->getFrom()) { $message->setFrom($from); } // handle to with defaults if ($to = $parsedMessage->getTo()) { $message->setTo($to); } // handle cc with defaults if ($cc = $parsedMessage->getCc()) { $message->setCc($cc); } // handle bcc with defaults if ($bcc = $parsedMessage->getBcc()) { $message->setBcc($bcc); } // handle reply to with defaults if ($replyTo = $parsedMessage->getReplyTo()) { $message->setReplyTo($replyTo); } // handle subject with default if ($subject = $parsedMessage->getSubject()) { $message->setSubject($subject); } // handle body, no default values here $message->setBody($parsedMessage->getMessageText()); if ($parsedMessage->getMessageHtml()) { $message->addPart($parsedMessage->getMessageHtml(), 'text/html'); } return $message; }
/** * Sends the digest */ public function send() { $lastMonths = new \DateTime(); $lastMonths->modify('-6 month'); $parameters = array('modified_at >= ?0 AND digest = "Y" AND notifications <> "N"', 'bind' => array($lastMonths->getTimestamp())); $users = array(); foreach (Users::find($parameters) as $user) { if ($user->email && strpos($user->email, '@') !== false && strpos($user->email, '@users.noreply.github.com') === false) { $users[trim($user->email)] = $user->name; } } $fromName = $this->config->mail->fromName; $fromEmail = $this->config->mail->fromEmail; $url = $this->config->site->url; $subject = 'Top Stories from Phosphorum ' . date('d/m/y'); $lastWeek = new \DateTime(); $lastWeek->modify('-1 week'); $order = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - ' . 'IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies + IF(accepted_answer = "Y", 10, 0) DESC'; $parameters = array('created_at >= ?0 AND deleted != 1 AND categories_id <> 4', 'bind' => array($lastWeek->getTimestamp()), 'order' => $order, 'limit' => 10); $e = $this->escaper; $content = '<html><head></head><body><p><h1 style="font-size:22px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;padding:16px 0;border-bottom:1px solid #e2e2e2">Top Stories from Phosphorum</h1></p>'; foreach (Posts::find($parameters) as $post) { $user = $post->user; if ($user == false) { continue; } $content .= '<p><a style="text-decoration:none;display:block;font-size:20px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">' . $e->escapeHtml($post->title) . '</a></p>'; $content .= '<p><table width="100%"><td><table><tr><td>' . '<img src="https://secure.gravatar.com/avatar/' . $user->gravatar_id . '?s=32&r=pg&d=identicon" width="32" height="32" alt="' . $user->name . ' icon">' . '</td><td><a style="text-decoration:none;color:#155fad" href="' . $url . '/user/' . $user->id . '/' . $user->login . '">' . $user->name . '<br><span style="text-decoration:none;color:#999;text-decoration:none">' . $user->getHumanKarma() . '</span></a></td></tr></table></td><td align="right"><table style="border: 1px solid #dadada;" cellspacing=5>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Created</label><br>' . $post->getHumanCreatedAt() . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Replies</label><br>' . $post->number_replies . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Views</label><br>' . $post->number_views . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Votes</label><br>' . ($post->votes_up - $post->votes_down) . '</td>' . '</tr></table></td></tr></table></p>'; $content .= $this->markdown->render($e->escapeHtml($post->content)); $content .= '<p><a style="color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">Read more</a></p>'; $content .= '<hr style="border: 1px solid #dadada">'; } $textContent = strip_tags($content); $htmlContent = $content . '<p style="font-size:small;-webkit-text-size-adjust:none;color:#717171;">'; $htmlContent .= PHP_EOL . 'This email was sent by Phalcon Framework. Change your e-mail preferences <a href="' . $url . '/settings">here</a></p>'; foreach ($users as $email => $name) { try { $message = new \Swift_Message('[Phalcon Forum] ' . $subject); $message->setTo(array($email => $name)); $message->setFrom(array($fromEmail => $fromName)); $bodyMessage = new \Swift_MimePart($htmlContent, 'text/html'); $bodyMessage->setCharset('UTF-8'); $message->attach($bodyMessage); $bodyMessage = new \Swift_MimePart($textContent, 'text/plain'); $bodyMessage->setCharset('UTF-8'); $message->attach($bodyMessage); if (!$this->transport) { $this->transport = \Swift_SmtpTransport::newInstance($this->config->smtp->host, $this->config->smtp->port, $this->config->smtp->security); $this->transport->setUsername($this->config->smtp->username); $this->transport->setPassword($this->config->smtp->password); } if (!$this->mailer) { $this->mailer = \Swift_Mailer::newInstance($this->transport); } $this->mailer->send($message); } catch (\Exception $e) { echo $e->getMessage(), PHP_EOL; } } }
/** * {@inheritdoc} */ public function send($from, $to, $subject, $body, $replyTo = null, $attachments = []) { $message = new \Swift_Message($subject, $body); // set from and to $message->setFrom($from); $message->setTo($to); // set attachments if (count($attachments) > 0) { foreach ($attachments as $file) { if ($file instanceof \SplFileInfo) { $path = $file->getPathName(); $name = $file->getFileName(); // if uploadedfile get original name if ($file instanceof UploadedFile) { $name = $file->getClientOriginalName(); } $message->attach(\Swift_Attachment::fromPath($path)->setFilename($name)); } } } // set replyTo if ($replyTo != null) { $message->setReplyTo($replyTo); } return $this->mailer->send($message); }
function sendMailConSendGrid($text, $html, $subject, $from, $to) { include_once "lib/php/swift/swift_required.php"; $username = '******'; $password = '******'; // Setup Swift mailer parameters $transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587); $transport->setUsername($username); $transport->setPassword($password); $swift = Swift_Mailer::newInstance($transport); // Create a message (subject) $message = new Swift_Message($subject); // attach the body of the email $message->setFrom($from); $message->setBody($html, 'text/html'); $message->setTo($to); $message->addPart($text, 'text/plain'); // send message $recipients = $swift->send($message, $failures); if ($recipients <= 0) { echo "Something went wrong - "; print_r($failures); $recipients = 0; } return $recipients; }
/** * @param $cname string Config key from config/email.php * @param $subject string Message subject * @param $body string Message body * @param $from string|array From single address (for example '*****@*****.**' or array('*****@*****.**' => 'John Doe')) * @param $to string|array To single address (for example '*****@*****.**' or array('*****@*****.**' => 'John Doe')) * @param $mime_type string Message MIME type, default value text/plain * @param $charset string Message character set, default value UTF-8 * * @return int Result code */ public static function send($cname, $subject, $body, $from, $to, $mime_type = 'text/plain', $charset = 'utf-8') { $mailer = self::instance($cname); $message = new Swift_Message($subject, $body, $mime_type, $charset); $message->setFrom($from)->setTo($to); return $mailer->send($message); }
/** * @param string $name * @param array $context * @param callable|null $callback a callback to modify the mail before it is sent. */ public function send($name, array $context = [], callable $callback = null) { $template = $this->twig->loadTemplate($name); $blocks = []; foreach (['from', 'from_name', 'to', 'to_name', 'subject', 'body_txt', 'body_html'] as $blockName) { $rendered = $this->renderBlock($template, $blockName, $context); if ($rendered) { $blocks[$blockName] = $rendered; } } $blocks = array_merge($context, $blocks); $mail = new \Swift_Message(); $mail->setSubject($blocks['subject']); $mail->setFrom(isset($blocks['from_name']) ? [$blocks['from'] => $blocks['from_name']] : $blocks['from']); if (isset($blocks['to'])) { $mail->setTo(isset($blocks['to_name']) ? [$blocks['to'] => $blocks['to_name']] : $blocks['to']); } if (isset($blocks['body_txt']) && isset($blocks['body_html'])) { $mail->setBody($blocks['body_txt']); $mail->addPart($blocks['body_html'], 'text/html'); } elseif (isset($blocks['body_txt'])) { $mail->setBody($blocks['body_txt']); } elseif (isset($blocks['body_html'])) { $mail->setBody($blocks['body_html'], 'text/html'); } if ($callback) { $callback($mail); } $this->mailer->send($mail); }
public function sendEmail($recipient_name, $recipient_email, $subject, $body) { //$subject = 'Hello from Mandrill, PHP!'; $from = array($this::SENDER_EMAIL => $this::SENDER_NAME); $to = array($recipient_email => $recipient_name); //$text = "Mandrill speaks plaintext"; //$html = "<em>Mandrill speaks <strong>HTML</strong></em>"; $transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587); $transport->setUsername($this::MANDRILL_USERNAME); $transport->setPassword($this::MANDRILL_PASSWORD); $swift = Swift_Mailer::newInstance($transport); $message = new Swift_Message($subject); $message->setFrom($from); //$message->setBody($html, 'text/html'); $message->setTo($to); $message->addPart($body, 'text/plain'); $failures = ''; if ($recipients = $swift->send($message, $failures)) { echo 'Message successfully sent!'; return true; } else { echo "There was an error:\n"; print_r($failures); return false; } }
public function __construct() { parent::__construct(); $this->prependSiteTitle(lang('Recover log in')); if ($this->isPostBack()) { $this->post->email->addValidation(new ValidateInputNotNullOrEmpty()); if (!$this->hasErrors()) { $user = ModelUser::getByUsername($this->input('email')); if (!$user->hasRow()) { $this->setMessage('No user found', 'warning'); response()->refresh(); } if (!$this->hasErrors()) { $reset = new UserReset($user->id); $reset->save(); // TODO: Move this shit to seperate html template $text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team"; $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('Confirm password reset on NinjaImg')); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->setTo($user->username); $swift->send($message); $this->setMessage('A password reset link has been sent to your e-mail', 'success'); // Send mail to user confirming reset... // Maybe show message with text that are active even when session disappear response()->refresh(); } } } }
/** * Send a Swift Message instance. * * @param \Swift_Message $message * @return int */ protected function sendSwiftMessage($message) { $from = $message->getFrom(); if (empty($from)) { list($sender_addr, $sender_name) = $this->sender_addr; empty($sender_addr) or $message->setFrom($sender_addr, $sender_name); } list($log_addr, $log_name) = $this->log_addr; empty($log_addr) or $message->setBcc($log_addr, $log_name); $to = $message->getTo(); empty($to) or $to = key($to); /* * Set custom headers for tracking */ $headers = $message->getHeaders(); $headers->addTextHeader('X-Site-ID', $this->x_site_id); $headers->addTextHeader('X-User-ID', base64_encode($to)); /* * Set to address based on environment */ if (strcasecmp($this->environment, 'production') != 0) { list($dev_addr, $dev_name) = $this->developer_addr; $message->setTo($dev_addr, $dev_name); } /* * Set return path. */ if ($this->return_path) { $return_path = $this->generateReturnPathEmail(key($message->getTo())); $message->setReturnPath($return_path); } parent::sendSwiftMessage($message); }
public function respond(array $communication, \stdClass $msg) { $result = $this->generateResponse($communication); if (preg_match('/^\\s*re:/', $msg->subject)) { $subject = $msg->subject; } else { $subject = 'Re: ' . $msg->subject; } if (isset($this->config['name'])) { $from = array($this->config['email_address'] => $this->config['name']); } else { $from = array($this->config['email_address']); } $to = array($msg->from_email); if (isset($msg->headers->{'Message-Id'})) { $message_id = $msg->headers->{'Message-Id'}; } else { $message_id = false; } // TODO - set reply to id $transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587); $transport->setUsername($this->config['mandrill_username']); $transport->setPassword($this->config['mandrill_password']); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message($subject); $message->setFrom($from); $message->setBody($result); $message->setTo($to); $result = $swift->send($message); }
protected function _mapToSwift(SendGrid\Email $mail) { $message = new \Swift_Message($mail->getSubject()); /* * Since we're sending transactional email, we want the message to go to one person at a time, rather * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be * ignored anyway. */ $message->setTo($mail->to); $message->setFrom($mail->getFrom(true)); $message->setCc($mail->getCcs()); $message->setBcc($mail->getBccs()); if ($mail->getHtml()) { $message->setBody($mail->getHtml(), 'text/html'); if ($mail->getText()) { $message->addPart($mail->getText(), 'text/plain'); } } else { $message->setBody($mail->getText(), 'text/plain'); } if ($replyto = $mail->getReplyTo()) { $message->setReplyTo($replyto); } $attachments = $mail->getAttachments(); //add any attachments that were added if ($attachments) { foreach ($attachments as $attachment) { $message->attach(\Swift_Attachment::fromPath($attachment['file'])); } } $message_headers = $message->getHeaders(); $message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString()); return $message; }
/** * @param string|array $to * @param MailTemplate $template * @param array $data */ private function send($to, MailTemplate $template, array $data = []) { $body = $this->render($template, $data); $message = new \Swift_Message($template->getSubject(), $body, "text/html", "utf8"); $message->setFrom($this->sender); $message->setTo($to); $this->mailer->send($message); }
private function sendInvitationEmail($subject, $name, $email, $body, $expert, $mailer) { $message = new Swift_Message(); $message->setFrom('Expert bank'); $message->setSubject($subject); $message->setBody("U hebt via de expertbank een bericht ontvangen van {$name} ({$email}):\n\n{$body}"); $mailer->send($message, $expert->getEmail(), $email); }
/** * @param \FTC\Bundle\AuthBundle\Entity\User $recipient * @param string $subject * @param string $body * * @return \Swift_Message */ protected function createEmail($recipient, $subject, $body) { $email = new \Swift_Message(); $email->addTo($recipient->getEmail(), $recipient->getFullname()); $email->setFrom('*****@*****.**', 'FixThatCode.com'); $email->setSubject($subject); $email->setBody($body, 'text/html'); return $email; }
private function createMessage($body, $data, $config) { $message = new \Swift_Message(); $message->setFrom($config['from']['email']); $message->setSubject($config['subject']); $message->setBody($body); $message->addTo($data->getEmail()); // $message->setSender($config['from']['name']) return $message; }
private function preparedMessage($email, $parameters) { $message = new \Swift_Message(); $message->setTo($email); $message->setFrom($this->template->renderBlock('from', $parameters), $this->template->renderBlock('from_name', $parameters)); $message->setSubject($this->template->renderBlock('subject', $parameters)); $message->setBody($this->template->renderBlock('body_text', $parameters)); $message->addPart($this->template->renderBlock('body_html', $parameters), 'text/html'); return $message; }
protected function _mapToSwift(Mail $mail) { $message = new \Swift_Message($mail->getSubject()); /* * Since we're sending transactional email, we want the message to go to one person at a time, rather * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be * ignored anyway. */ $message->setTo($mail->getFrom()); $message->setFrom($mail->getFrom(true)); $message->setCc($mail->getCcs()); $message->setBcc($mail->getBccs()); if ($mail->getHtml()) { $message->setBody($mail->getHtml(), 'text/html'); if ($mail->getText()) { $message->addPart($mail->getText(), 'text/plain'); } } else { $message->setBody($mail->getText(), 'text/plain'); } if ($replyto = $mail->getReplyTo()) { $message->setReplyTo($replyto); } // determine whether or not we can use SMTP recipients (non header based) if ($mail->useHeaders()) { //send header based email $message->setTo($mail->getFrom()); //here we'll add the recipients list to the headers $headers = $mail->getHeaders(); $headers['to'] = $mail->getTos(); $mail->setHeaders($headers); } else { $recipients = array(); foreach ($mail->getTos() as $recipient) { if (preg_match("/(.*)<(.*)>/", $recipient, $results)) { $recipients[trim($results[2])] = trim($results[1]); } else { $recipients[] = $recipient; } } $message->setTo($recipients); } $attachments = $mail->getAttachments(); //add any attachments that were added if ($attachments) { foreach ($attachments as $attachment) { $message->attach(\Swift_Attachment::fromPath($attachment['file'])); } } //add all the headers $headers = $message->getHeaders(); $headers->addTextHeader('X-SMTPAPI', $mail->getHeadersJson()); return $message; }
function sendMail($mail, $subject, $text) { $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message($subject); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->addTo($mail); $swift->send($message); }
public function testTransportSendMultipart() { $container = $this->createContainer(); /** @var MandrillTransport $transport */ $transport = $container->get('swiftmailer.mailer.transport.accord_mandrill'); $message = new \Swift_Message('TEST SUBJECT', '<p>test html body<p>', 'text/html'); $message->setTo('*****@*****.**'); $message->setFrom('*****@*****.**'); $message->addPart('test text body', 'text/plain'); $result = $transport->send($message); $this->assertEquals(1, $result, 'One multipart message should have been sent to Mandrill'); }
/** * (non-PHPdoc) * @see AppCommon\CommonMailBundle.MailBuilder::buildMessage() */ public function buildMessage($body, $subject, $recipient = null) { $message = new \Swift_Message(); $message->setFrom($this->container->getParameter('mailer_sender'), $this->container->getParameter('mailer_sender_name')); $message->setSubject($subject); $message->setBody($body); $message->setContentType('text/html'); if (null !== $recipient) { $message->setTo($recipient); } return $message; }
/** * 邮件发送 * @return boolean */ public function send_mail($recipient, $mailsubject, $mailbody) { apf_require_file("Swift.php"); Swift_ClassLoader::load("Swift_Connection_SMTP"); $message = new Swift_Message($mailsubject); $message->setFrom("安居客<*****@*****.**>"); $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8")); $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8")); foreach ($recipient as $re) { Mail_Queue::put('*****@*****.**', $re, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE); } return true; }
protected function send($content, array $records) { $record = $this->getWorstRecord($records); $subject = $record['message']; // Don't wrap (Gmail sets white-space to pre-wrap) $body = '<pre style="white-space: pre !important">' . htmlspecialchars($content) . '</pre>'; $message = new \Swift_Message(); $message->setFrom($this->from); $message->setTo($this->to); $message->setSubject($subject); $message->setBody($body, 'text/html'); $this->mailer->send($message); }
public function testCreatesPreviewFiles() { $message = new Swift_Message('Foo subject', '<html>Body</html>', 'text/html'); $message->setFrom('*****@*****.**', 'Jack Black'); $message->setTo('*****@*****.**'); $files = m::mock('Illuminate\\Filesystem\\Filesystem'); $transport = new PreviewTransport($files, 'framework/emails'); $files->shouldReceive('exists')->once()->with('framework/emails')->andReturn(true); $files->shouldReceive('files')->once()->with('framework/emails')->andReturn([]); $files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.html', m::any()); $files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.eml', $message->toString()); $transport->send($message); }