本文整理汇总了PHP中Swift_Message::setTo方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::setTo方法的具体用法?PHP Swift_Message::setTo怎么用?PHP Swift_Message::setTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::setTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: to
/**
* Add a recipient to the message.
*
* @param string|array $address
* @param string|null $name
* @param bool $override
* @return $this
*/
public function to($address, $name = null, $override = false)
{
if ($override) {
return $this->swift->setTo($address, $name);
}
return $this->addAddresses($address, $name, 'To');
}
示例2: send
/**
* @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);
}
示例3: setGroup
public function setGroup($name)
{
$mailTo = $this->mailerConfig->getMailToByGroupName($name);
if ($mailTo) {
$this->message->setTo($mailTo->getMailTo());
return true;
}
return false;
}
示例4: _mapToSwift
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;
}
示例5: iSendEmailWithMessage
/**
* @When I send email to :email with message :body
*/
public function iSendEmailWithMessage($email, $body)
{
$message = new \Swift_Message('Subject', $body);
$message->setSender('john@example.com');
$message->setTo($email);
$this->sendEmail($message);
}
示例6: respond
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);
}
示例7: sendMailConSendGrid
function sendMailConSendGrid($text, $html, $subject, $from, $to)
{
include_once "lib/php/swift/swift_required.php";
$username = 'unovamx';
$password = 'LanzamientoUnova2012';
// 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;
}
示例8: send
/**
* @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);
}
示例9: sendEmail
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;
}
}
示例10: __construct
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();
}
}
}
}
示例11: sendSwiftMessage
/**
* 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);
}
示例12: transformMessage
/**
* 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;
}
示例13: send
/**
* {@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);
}
示例14: send
/**
* 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;
}
}
}
示例15: send
/**
* @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;
}
}