本文整理汇总了PHP中Zend\Mail\Message::setSubject方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::setSubject方法的具体用法?PHP Message::setSubject怎么用?PHP Message::setSubject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mail\Message
的用法示例。
在下文中一共展示了Message::setSubject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildMessage
/**
* Build Message
*
* @return MailMessage
*/
public function buildMessage()
{
// prepare html body
$htmlBody = $this->renderer->render($this->viewModel);
// prepare text body
$textBody = $this->buildTextBody($htmlBody);
// prepare subject
$subject = $this->buildSubject($htmlBody);
// prepare html part
$htmlPart = new MimePart($this->buildHtmlHeader() . $htmlBody . $this->buildHtmlFooter());
$htmlPart->type = 'text/html';
// prepare text part
$textPart = new MimePart($textBody);
$textPart->type = 'text/plain';
// prepare mime message
$mailBody = new MimeMessage();
$mailBody->setParts(array($textPart, $htmlPart));
// prepare message
$this->message = new MailMessage();
$this->message->setEncoding($this->encoding);
$this->message->setFrom($this->senderMail, $this->senderName);
$this->message->setSubject($subject);
$this->message->setBody($mailBody);
// return mailer
return $this;
}
示例2: 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);
}
示例3: addAction
/**
* Add Action
* <br/> Responsible for :
* <br/>In case Get verb -> Display Add new Book Form
* <br/>In case Post verb -> Add new book details into Database
* After Submit Book Form
* @return ViewModel add view
*/
public function addAction()
{
$form = new BookForm();
$form->get('submit')->setValue('Add');
// Another way to set Submit button value
// $form->get('submit')->setAttribute('value', 'Add');
$request = $this->getRequest();
// Check If request is Post verb
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 an email when a new book Was Added
$mail = new Mail\Message();
$mail->setBody('A new Book called ' . $book->title . ' has been added.');
$mail->setFrom('ahmedhamdy20@gmail.com', 'Zend course');
$mail->addTo('ahmedhamdy20@gmail.com', 'Ahmed Hamdy');
$mail->setSubject('A Book was Added');
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
}
// redirect to list of books
return $this->redirect()->toRoute('book');
}
return new ViewModel(array('form' => $form));
}
示例4: sendMail
/**
* @param ZendMail\Message $message
* @param string $emailAlias
* @param array $variables
* @return ZendMail\Message
* @throws Exception\RuntimeException
*/
public function sendMail(ZendMail\Message $message, $emailAlias, array $variables = array())
{
$plain = $this->renderMessage($emailAlias, Config::TYPE_PLAIN, $variables);
$html = $this->renderMessage($emailAlias, Config::TYPE_HTML, $variables);
$body = new Mime\Message();
if (!empty($html) && !empty($plain)) {
$htmlPart = new Mime\Part($html);
$htmlPart->type = 'text/html';
$plainPart = new Mime\Part($plain);
$plainPart->type = 'text/plain';
$body->setParts(array($plainPart, $htmlPart));
} elseif (!empty($html)) {
$htmlPart = new Mime\Part($html);
$htmlPart->type = 'text/html';
$body->setParts(array($htmlPart));
} else {
$plainPart = new Mime\Part($plain);
$plainPart->type = 'text/plain';
$body->setParts(array($plainPart));
}
$from = $this->getConfig()->getFrom($emailAlias);
$message->setSubject($this->getSubject($emailAlias, $variables))->setEncoding('UTF-8')->setBody($body)->setFrom($from['email'], $from['name']);
if (count($body->getParts()) == 2) {
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
}
if (null === ($transport = $this->getTransport())) {
throw new Exception\RuntimeException('No transport could be alocated');
}
$transport->send($message);
return $message;
}
示例5: send
public function send($fromAddress, $fromName, $replyToAddress, $replyToName, $toAddress, $toName, $subject, array $mimeParts)
{
$mail = new Message();
if ($fromAddress && $fromName) {
$mail->setFrom($fromAddress, $fromName);
} else {
if ($fromAddress) {
$mail->setFrom($fromAddress);
}
}
if ($replyToAddress && $replyToName) {
$mail->setReplyTo($replyToAddress, $replyToName);
} else {
if ($replyToAddress) {
$mail->setReplyTo($replyToAddress);
}
}
if ($toAddress && $toName) {
$mail->setTo($toAddress, $toName);
} else {
if ($toAddress) {
$mail->setTo($toAddress);
}
}
$mail->setSubject($subject);
$mail->setEncoding('utf-8');
$mime = new MimeMessage();
$mime->setParts($mimeParts);
$mail->setBody($mime);
$this->mailTransport->send($mail);
$this->getEventManager()->trigger('send', $mail);
}
示例6: render
/**
* @param Message $message
* @return Message
*/
public function render(Message $message)
{
$viewModel = new ViewModel($this->variables);
$viewModel->setTemplate($this->template);
$helperPluginManager = $this->renderer->getHelperPluginManager();
/** @var HeadTitle $helper */
$helper = $helperPluginManager->get('HeadTitle');
// replace headTitle
$headTitle = new HeadTitle();
$headTitle->setAutoEscape(false);
$helperPluginManager->setAllowOverride(true);
$helperPluginManager->setService('HeadTitle', $headTitle);
if (!$message->getBody()) {
$message->setBody(new MimeMessage());
}
$text = new Part($this->renderer->render($viewModel));
$text->charset = 'UTF-8';
$text->boundary = $message->getBody()->getMime()->boundary();
$text->encoding = Mime::ENCODING_BASE64;
$text->type = Mime::TYPE_HTML;
$message->getBody()->addPart($text);
$message->setSubject($headTitle->renderTitle());
// hack for ZF
$message->setBody($message->getBody());
// restore original helper
$helperPluginManager->setService('HeadTitle', $helper);
return $message;
}
示例7: 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()]);
}
示例8: 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;
}
示例9: testTrue
public function testTrue()
{
$message = new Message();
$message->setSubject('Hundur')->setBody(file_get_contents(__DIR__ . '/mail.test.01.txt'))->addFrom('ble@bla.is', 'ble')->addTo('hundur@vei.is', 'hundur');
$attacher = new Attacher($message);
$result = $attacher->parse();
}
示例10: sendEmail
public function sendEmail($from, $to, $cc, $subject, $body, $attachmentFilename)
{
$message = new Message();
$message->setFrom($from);
$message->setTo($to);
$message->setCc($cc);
$message->setSubject($subject);
$mimeMessage = new \Zend\Mime\Message();
$part = new \Zend\Mime\Part($body);
$part->setType(Mime::TYPE_TEXT);
$part->setCharset('UTF-8');
$mimeMessage->addPart($part);
$part = new \Zend\Mime\Part('<p>' . $body . '<p>');
$part->setType(Mime::TYPE_HTML);
$part->setCharset('UTF-8');
$mimeMessage->addPart($part);
$part = new \Zend\Mime\Part($body);
$part->setType(Mime::TYPE_OCTETSTREAM);
$part->setEncoding(Mime::ENCODING_BASE64);
$part->setFileName($attachmentFilename);
$part->setDisposition(Mime::DISPOSITION_ATTACHMENT);
$mimeMessage->addPart($part);
$message->setBody($mimeMessage);
$this->transport->send($message);
$this->debugSection('ZendMailer', $subject . ' ' . $from . ' -> ' . $to);
}
示例11: 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;
}
示例12: sendAction
/**
* Send email to contacts, insert message into db, log operation
*/
public function sendAction()
{
$form = new ContactsForm();
$request = $this->getRequest();
if ($request->isPost()) {
$mainLayout = $this->initializeFrontendWebsite();
$em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$inputFilter = new ContactsFormInputFilter();
$form->setInputFilter($inputFilter->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$inputFilter->exchangeArray($form->getData());
$formData = $request->getPost();
$configurations = $this->layout()->getVariable('configurations');
$mail = new Mail\Message();
$mail->setFrom($configurations['emailnoreply'], $formData->nome . ' ' . $formData->cognome);
$mail->addTo($configurations['emailcontact'], $configurations['sitename']);
$mail->setSubject('Nuovo messaggio dal sito ' . $configurations['sitename']);
$mail->setBody("Nome e cognome: \n " . $formData->nome . " " . $formData->cognome . " Email: " . $formData->email . "\n Messaggio: " . $formData->messaggio);
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
$helper = new ContactsControllerHelper();
$helper->setConnection($em->getConnection());
$helper->insert($inputFilter);
$this->layout()->setVariables(array('configuraitions' => $configurations, 'homepage' => !empty($homePageElements) ? $homePageElements : null, 'templatePartial' => 'contatti/ok.phtml'));
$this->layout()->setTemplate($mainLayout);
} else {
foreach ($form->getInputFilter()->getInvalidInput() as $invalidInput) {
var_dump($form->getMessages());
}
exit;
}
}
}
示例13: sendMail
/**
* @param string $subject
* @param string $message
* @param null|string|array $to
* @param null|string|array $cc
* @param null|string|array $bcc
* @return array
*/
public function sendMail($subject, $message, $to = null, $cc = null, $bcc = null)
{
$return = array('success' => true, 'msg' => null);
$partBody = new MimePart($this->getPartHeader() . $message . $this->getPartFooter());
$partBody->type = Mime::TYPE_HTML;
$partBody->charset = 'utf-8';
$this->body->setParts(array($partBody));
$subject = '[' . APPLICATION_NAME . '] ' . $subject;
$mail = new Message();
$mail->addFrom(self::FROM);
$mail->setSubject($subject);
$mail->setBody($this->body);
$mail->setTo($to);
if ($cc) {
$mail->setCc($cc);
}
if ($bcc) {
$mail->setBcc($bcc);
}
try {
$this->transport->send($mail);
} catch (\Exception $e) {
$return['success'] = false;
$return['msg'] = _('mail.message.not_sent');
//throw new \Exception($e->getMessage(), $e->getCode());
}
return $return;
}
示例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: sendCertificate
/**
* Sends award certificate
*
* @param \User\Model\Entity\User $user
* @param array $exam
* @param \ZendPdf\Document $pdf
*/
public function sendCertificate($user, $exam, $pdf)
{
$translator = $this->services->get('translator');
$mail = new Message();
$mail->addTo($user->getEmail(), $user->getName());
$text = 'You are genius!
You answered all the questions correctly.
Therefore we are sending you as a gratitude this free award certificate.
';
// we create a new mime message
$mimeMessage = new MimeMessage();
// create the original body as part
$textPart = new MimePart($text);
$textPart->type = "text/plain";
// add the pdf document as a second part
$pdfPart = new MimePart($pdf->render());
$pdfPart->type = 'application/pdf';
$mimeMessage->setParts(array($textPart, $pdfPart));
$mail->setBody($mimeMessage);
$mail->setFrom('slavey@zend.com', 'Slavey Karadzhov');
$mail->setSubject($translator->translate('Congratulations: Here is your award certificate'));
$transport = $this->services->get('mail-transport');
$transport->send($mail);
}