本文整理匯總了PHP中Zend\Mail\Message::addTo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Message::addTo方法的具體用法?PHP Message::addTo怎麽用?PHP Message::addTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Mail\Message
的用法示例。
在下文中一共展示了Message::addTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendEmail
private function sendEmail(array $listaEmailTo, array $listaEmailCC, $subject, $msg)
{
$renderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $renderer->render('email/template', array('msg' => nl2br($msg)));
// make a header as html(template)
$html = new MimePart($content);
$html->type = "text/html";
// make a image inline
$image = new MimePart(fopen(__DIR__ . '\\..\\..\\..\\..\\Frota\\view\\email\\fundo_email_checkin.png', 'r'));
$image->type = "image/jpeg";
$image->id = "fundo_mail";
$image->disposition = "inline";
// build an email with a text(html) + image(inline)
$body = new MimeMessage();
$body->setParts(array($html, $image));
// instance mail
$mail = new Mail\Message();
$mail->setBody($body);
// will generate our code html from template.phtml
$mail->setFrom($this->from['email'], utf8_decode($this->from['nome']));
$mail->addTo($listaEmailTo);
//$mail->addCc($listaEmailCC);
$mail->setSubject(utf8_decode($subject));
$transport = new Mail\Transport\Smtp($this->options);
try {
$transport->send($mail);
} catch (RuntimeException $exc) {
$this->logger->info('Erro ao enviar email para: ' . implode(',', $listaEmailTo) . ' erro: ' . $exc->getMessage() . "\n" . $exc->getTraceAsString());
if ($exc->getMessage() == 'Could not open socket') {
throw new Exception('O serviço de e-mail do MPM está indisponível no momento, a mensagem não foi enviada!');
}
throw new Exception("Não foi possível enviar a mensagem, ocorreu o seguinte erro: {$exc->getMessage()}!");
}
}
示例2: getMessage
public function getMessage()
{
$message = new Message();
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam')->addCc('matthew@zend.com')->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project')->addFrom(array('zf-devteam@zend.com', 'Matthew' => 'matthew@zend.com'))->setSender('ralph.schindler@zend.com', 'Ralph Schindler')->setSubject('Testing Zend\\Mail\\Transport\\Sendmail')->setBody('This is only a test.');
$message->getHeaders()->addHeaders(array('X-Foo-Bar' => 'Matthew'));
return $message;
}
示例3: send
public function send($subject, $text, $to, $from = null)
{
if (!config('mail.enabled')) {
return;
}
$message = new Message();
$message->setSubject($subject);
if ($from) {
if (is_array($from)) {
$message->setFrom($from[0], $from[1]);
} else {
$message->setFrom($from);
}
}
$message->addTo($to);
$content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>';
$html = new Mime\Part($content);
$html->setType(Mime\Mime::TYPE_HTML);
$html->setCharset('utf-8');
$mimeMessage = new Mime\Message();
$mimeMessage->addPart($html);
foreach ($this->attachments as $attachment) {
$mimeMessage->addPart($attachment);
}
$message->setBody($mimeMessage);
try {
$transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
$transport->send($message);
} catch (\Exception $e) {
throw $e;
}
return $this;
}
示例4: send
function send()
{
//第一步: 設置相關的headers
//1.設置郵件的Content-Type,要不然網站的消息內容裏麵的html標簽會被當做純文本處理
$smtpHeaderContentType = new SmtpHeaderContentType();
$smtpHeaderContentType->setType('text/html');
//2.設置編碼集並添加Content-Type
$headers = new SmtpHeaders();
$headers->setEncoding('utf-8');
$headers->addHeader($smtpHeaderContentType);
//第二步:設置消息的相關
$message = new SmtpMessage();
$message->setHeaders($headers);
$message->addTo($this->mailTo)->addFrom($this->mailFrom)->setSubject($this->subject)->setBody($this->body);
//郵件的內容
//第三步:設置Smtp的相關鏈接參數
$smtpOptions = new SmtpOptions();
$smtpOptions->setHost($this->host)->setPort($this->port)->setConnectionClass('login')->setConnectionConfig(array('username' => $this->username, 'password' => $this->password, 'ssl' => 'ssl'));
//第四步:加載配置,發送消息
$smtpTransport = new SmtpTransport();
$smtpTransport->setOptions($smtpOptions);
//加載配置
$smtpTransport->send($message);
//發送消息
}
示例5: sendMail
/**
* Sends a mail with the given data from the AppMailAccount
* @param string $to
* @param string $subject
* @param string $content
*/
public function sendMail(string $to, string $subject, string $content, array $files = [])
{
$content .= "\n\nThis is an automated mail. Please don't respond.";
$text = new Mime\Part($content);
$text->type = 'text/plain';
$text->charset = 'utf-8';
$text->disposition = Mime\Mime::DISPOSITION_INLINE;
$parts[] = $text;
foreach ($files as $filePath) {
$fileContent = file_get_contents($filePath);
$attachment = new Mime\Part($fileContent);
$attachment->type = 'image/' . pathinfo($filePath, PATHINFO_EXTENSION);
$attachment->filename = basename($filePath);
$attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Mime\Mime::ENCODING_BASE64;
$parts[] = $attachment;
}
$mime = new Mime\Message();
$mime->setParts($parts);
$appMailData = $this->getAppMailData();
$message = new Message();
$message->addTo($to)->addFrom($appMailData->getAdress())->setSubject($subject)->setBody($mime)->setEncoding('utf-8');
$transport = new SmtpTransport();
$options = new SmtpOptions(['name' => $appMailData->getHost(), 'host' => $appMailData->getHost(), 'connection_class' => 'login', 'connection_config' => ['username' => $appMailData->getLogin(), 'password' => $appMailData->getPassword()]]);
$transport->setOptions($options);
$transport->send($message);
}
示例6: sendEmailAction
protected function sendEmailAction()
{
$userTable = $this->getServiceLocator()->get('UserTable');
if (true) {
//$this->request->isPost()) {
$subject = 'subject';
//$this->request->getPost()->get('subject');
$body = 'body';
//$this->request->getPost()->get('body');
$fromUserId = 1;
//$this->user->id;
$toUserId = 2;
//$this->request->getPost()->get('toUserId');
$fromUser = $userTable->getUser($fromUserId);
$toUser = $userTable->getUser($toUserId);
$mail = new Mail\Message();
$mail->setFrom($fromUser->email, $fromUser->name);
$mail->addTo($toUser->email, $toUser->name);
$mail->setSubject($subject);
$mail->setBody($body);
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
}
return true;
}
示例7: sendRestPasswordEmail
/**
* send
*
* @param ResetPassword $resetPassword
* @param User $user
* @param array $mailConfig
*
* @return mixed
*/
public function sendRestPasswordEmail(ResetPassword $resetPassword, User $user, $mailConfig)
{
$toEmail = $user->getEmail();
$fromEmail = $mailConfig['fromEmail'];
$fromName = $mailConfig['fromName'];
$subject = $mailConfig['subject'];
$bodyTemplate = $mailConfig['body'];
//Ignore blank emails
if (!trim($toEmail)) {
return;
}
$vars = ['name' => '', 'userId' => $user->getId(), 'url' => 'https://' . $_SERVER['HTTP_HOST'] . '/reset-password?fromPasswordResetEmail=1&id=' . $resetPassword->getResetId() . '&key=' . $resetPassword->getHashKey()];
foreach ($vars as $name => $value) {
$bodyTemplate = str_replace('__' . $name . '__', $value, $bodyTemplate);
// Handle BC
$bodyTemplate = str_replace('{' . $name . '}', $value, $bodyTemplate);
}
try {
$html = new MimePart($bodyTemplate);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts([$html]);
$message = new Message();
$message->setBody($body)->setFrom($fromEmail, $fromName)->setSubject($subject);
foreach (explode(',', $toEmail) as $email) {
$message->addTo(trim($email));
}
$transport = new \Zend\Mail\Transport\Sendmail();
$transport->send($message);
} catch (InvalidArgumentException $e) {
// nothing
}
}
示例8: indexAction
public function indexAction()
{
$form = $this->getServiceLocator()->get('form.contact');
if ($this->getRequest()->isPost()) {
$post = $this->getRequest()->getPost()->toArray();
$form->setData($post);
if ($form->isValid()) {
$content = 'Name: ' . $post['name'] . "\n";
$content .= 'Email: ' . $post['email'] . "\n";
$content .= 'Message: ' . "\n" . $post['message'];
$message = new Message();
$message->addTo('hello@majorapps.co.uk');
$message->setSubject('MajorApps website contact');
$message->setBody($content);
$message->setFrom('rob@clocal.co.uk');
/** @var Smtp $transport */
$transport = $this->getServiceLocator()->get('mail.transport');
$transport->send($message);
// Fallback in-case email fails
$content = '=======================================' . "\n" . date('Y-m-d H:i:s') . "\n" . $content . "\n" . '=======================================' . "\n";
file_put_contents(__DIR__ . '/../../../../../data/message.txt', $content, FILE_APPEND);
$this->flashMessenger()->addSuccessMessage('Message sent successfully');
return $this->redirect()->toRoute('home');
} else {
$this->flashMessenger()->addErrorMessage('Message was not sent successfully');
}
}
return new ViewModel(['form' => $form, 'jargon' => $this->getJargon(), 'features' => $this->getFeatures()]);
}
示例9: sendContactMail
/**
* Send contact mail
* @param $controller
* @param $data
*/
public static function sendContactMail($controller, $data)
{
// prepare html content
$comments = nl2br($data['comments']);
// line break
$content = '';
$content .= '<table>';
$content .= '<tbody>';
$content .= "<tr><td>First Name:</td><td>{$data['firstName']}</td></tr>";
$content .= "<tr><td>Last Name:</td><td>{$data['lastName']}</td></tr>";
$content .= "<tr><td>Phone Number:</td><td>{$data['phone']}</td></tr>";
$content .= "<tr><td>Email:</td><td>{$data['email']}</td></tr>";
$content .= "<tr><td>Company:</td><td>{$data['company']}</td></tr>";
$content .= "<tr><td>Job Title:</td><td>{$data['jobTitle']}</td></tr>";
$content .= "<tr><td>Comments:</td><td>{$comments}</td></tr>";
$content .= '</tbody>';
$content .= '</table>';
$html = new MimePart($content);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html));
$message = new Message();
$message->setBody($body);
// subject
$subject = 'Contact from Papertask';
$message->setSubject($subject);
// get transport
$transport = $controller->getServiceLocator()->get('mail.transport');
$message->addTo($transport->mailOptions['contact']);
$message->addFrom($transport->mailOptions['contact']);
$transport->send($message);
}
示例10: send
function send($recipients, $type = 'mail')
{
global $tikilib, $prefs;
$logslib = TikiLib::lib('logs');
$this->mail->getHeaders()->removeHeader('to');
foreach ((array) $recipients as $to) {
$this->mail->addTo($to);
}
if ($prefs['zend_mail_handler'] == 'smtp' && $prefs['zend_mail_queue'] == 'y') {
$query = "INSERT INTO `tiki_mail_queue` (message) VALUES (?)";
$bindvars = array(serialize($this->mail));
$tikilib->query($query, $bindvars, -1, 0);
$title = 'mail';
} else {
try {
tiki_send_email($this->mail);
$title = 'mail';
} catch (Zend\Mail\Exception\ExceptionInterface $e) {
$title = 'mail error';
}
if ($title == 'mail error' || $prefs['log_mail'] == 'y') {
foreach ($recipients as $u) {
$logslib->add_log($title, $u . '/' . $this->mail->getSubject());
}
}
}
return $title == 'mail';
}
示例11: fromWrappedMessage
/**
* @inheritDoc
*/
public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null)
{
if (!$wrappedMessage instanceof MailWrappedMessage) {
throw new MailWrapperSetupException('Not MailWrappedMessage');
}
$message = new 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()) {
$html = new MimePart($wrappedMessage->getContentHtml());
$html->type = "text/html";
$message->setBody($body);
}
return $message;
}
示例12: addAction
public function addAction()
{
$form = new BookForm();
$form->get('submit')->setValue('Add');
$request = $this->getRequest();
if ($request->isPost()) {
$book = new Book();
$form->setInputFilter($book->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$book->exchangeArray($form->getData());
$this->getBookTable()->saveBook($book);
//send email
$mail = new Mail\Message();
$mail->setBody('A new book called ' . $book->title . ' has been added.');
$mail->setFrom('jp.ciphron@gmail.com', 'Zend Course');
$mail->addTo('jp.ciphron@gmail.com', 'Myself');
$mail->setSubject('A Book was added');
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
}
//Redirect to books list
return $this->redirect()->toRoute('book');
}
return array('form' => $form);
}
示例13: send
/**
* Sends the contact message via email
*
* @param array $data
* @return boolean
**/
public function send($data)
{
$form = $this->getForm();
$form->setData($data);
if ($form->isValid()) {
$data = $form->getData();
$message = 'Name: ' . $data['name'] . "\r\n";
$message .= 'Email: ' . $data['email'] . "\r\n\r\n";
$message .= $data['comment'];
$mail = new Message();
$mail->setBody($message);
$mail->setFrom('rob@robkeplin.com');
$mail->addTo('rkeplin@gmail.com', 'Rob Keplin');
$mail->setSubject('From robkeplin.com');
$transport = new Sendmail();
try {
$transport->send($mail);
} catch (RuntimeException $e) {
$this->addMessage('The email did not get sent due to sendmail failing. Doh!', self::MSG_ERROR);
return false;
}
$form->setData(array('name' => '', 'email' => '', 'comment' => ''));
$this->addMessage('Thanks. Get back to you soon!', self::MSG_NOTICE);
return true;
}
$this->addMessage('Hey, Wait! Something went wrong down there. Please fix the errors and try again.', self::MSG_ERROR);
return false;
}
示例14: sendOfflineMessage
protected function sendOfflineMessage($msgSubj, $msgText, $fromUserId, $toUserId)
{
$userTable = $this->getServiceLocator()->get('UserTable');
$fromUser = $userTable->getById($fromUserId);
$toUser = $userTable->getById($toUserId);
$mail = new Mail\Message();
$mail->setFrom($fromUser->getEmail(), $fromUser->getName());
$mail->addTo($toUser->getEmail(), $toUser->getName());
$mail->setSubject($msgSubj);
$mail->setBody($msgText);
$transport = new Mail\Transport\Sendmail();
// $transport = new Mail\Transport\Smtp();
// $options = new Mail\Transport\SmtpOptions(array(
// 'name' => 'smtp.gmail.com',
// 'host' => 'smtp.gmail.com',
// 'connection_class' => 'login',
// 'connection_config' => array(
// 'ssl' => 'tls',
// 'username' => 'seyferseed@gmail.com',
// 'password' => '',
// ),
// ));
// $transport->setOptions($options);
$transport->send($mail);
return true;
}
示例15: sendMessage
public function sendMessage(Message $message, Smtp $smtp, $recipient)
{
$message->addTo($recipient);
if (!$this->config['disable_delivery']) {
$smtp->send($message);
}
}