本文整理汇总了PHP中Zend\Mail\Message::setSender方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::setSender方法的具体用法?PHP Message::setSender怎么用?PHP Message::setSender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mail\Message
的用法示例。
在下文中一共展示了Message::setSender方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
/**
* @param null $user to username
* @param null $from from email
*/
function __construct($user = null, $from = null)
{
require_once 'lib/mail/maillib.php';
$userlib = TikiLib::lib('user');
$to = '';
if (!empty($user)) {
if ($userlib->user_exists($user)) {
$to = $userlib->get_user_email($user);
} else {
trigger_error('User not found');
return;
}
}
if (!empty($from)) {
$this->mail = tiki_get_basic_mail();
try {
$this->mail->setFrom($from);
$this->mail->setSender($from);
} catch (Exception $e) {
// was already set, then do nothing
}
} else {
$this->mail = tiki_get_admin_mail();
}
if (!empty($to)) {
$this->mail->addTo($to);
}
}
示例2: testSendMailWithoutRecipient
/**
* Per RFC 2821 3.3 (page 18)
* - RCPT (recipient) must be called before DATA (headers or body)
*/
public function testSendMailWithoutRecipient()
{
$this->setExpectedException('Zend\\Mail\\Transport\\Exception\\RuntimeException', 'at least one recipient if the message has at least one header or body');
$message = new Message();
$message->setSender('ralph.schindler@zend.com', 'Ralph Schindler');
$this->transport->send($message);
}
示例3: testSenderAccessorsProxyToSenderHeader
public function testSenderAccessorsProxyToSenderHeader()
{
$header = new Header\Sender();
$this->message->getHeaders()->addHeader($header);
$address = new Address('zf-devteam@zend.com', 'ZF DevTeam');
$this->message->setSender($address);
$this->assertSame($address, $header->getAddress());
}
示例4: createMessage
private function createMessage()
{
$message = new Message();
$config = $this->config['message'];
$message->addTo($config['to']);
if ($config['from']) {
$message->addFrom($config['from']);
}
$message->setSender($config['sender']['address'], $config['sender']['name']);
return $message;
}
示例5: sendMail
public function sendMail()
{
if (false === $this->checkMailValidity()) {
throw new \InvalidArgumentException('E-Mail can not be sent as the required fields where not filled in.');
}
$mimeBody = new MimeMessage();
if ($this->mailBodyHtml instanceof ViewModel) {
$htmlBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyHtml));
$htmlBodyPart->charset = $this->mailCharset;
$htmlBodyPart->encoding = $this->mailEncoding;
$htmlBodyPart->type = 'text/html';
$mimeBody->addPart($htmlBodyPart);
}
if ($this->mailBodyText instanceof ViewModel) {
$textBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyText));
$textBodyPart->charset = $this->mailCharset;
$textBodyPart->encoding = $this->mailEncoding;
$textBodyPart->type = 'text/plain';
$mimeBody->addPart($textBodyPart);
}
$mailMessage = new MailMessage();
$mailMessage->setBody($mimeBody);
$mailMessage->setEncoding($this->mailEncoding);
$mailMessage->setFrom($this->mailFrom);
$mailMessage->setSender($this->mailFrom);
$mailMessage->setTo($this->mailTo);
if ($this->mailBcc != '') {
$mailMessage->setBcc($this->mailBcc);
}
if ($this->mailCc != '') {
$mailMessage->setCc($this->mailCc);
}
$mailMessage->setSubject($this->mailSubject);
if (2 <= count($mimeBody->getParts())) {
$mailMessage->getHeaders()->get('content-type')->setType('multipart/alternative');
}
try {
$this->transport->send($mailMessage);
return true;
} catch (\Exception $e) {
throw new \Exception($e);
}
}
示例6: convert
/**
*
* @param Message $message
* @return ZendMessage
*/
public static function convert(Message $message)
{
$mailMessage = new ZendMessage();
$mailMessage->setSubject($message->getSubject());
$mailMessage->setFrom($message->getFrom());
$mailMessage->setTo($message->getTo());
$mailMessage->setCc($message->getCc());
$mailMessage->setBcc($message->getBcc());
$mailMessage->setReplyTo($message->getReplyTo());
$mailMessage->getHeaders()->addHeaders($message->getHeaders());
if ($mailMessage->getSender()) {
$mailMessage->setSender($message->getSender());
}
if ($message->isMultipart()) {
$mimePart = new MimeMessage();
if ($message->getBodyHtml()) {
$part = new Part($message->getBodyHtml());
$part->charset = $message->getCharset();
$part->encoding = $message->getEncoding();
$part->type = Mime::TYPE_HTML;
$mimePart->addPart($part);
}
if ($message->getBodyText()) {
$part = new Part($message->getBodyText());
$part->charset = $message->getCharset();
$part->encoding = $message->getEncoding();
$part->type = Mime::TYPE_TEXT;
$mimePart->addPart($part);
}
foreach ($message->getAttachments() as $attachment) {
$mimePart->addPart($attachment->asMimePart());
}
foreach ($message->getParts() as $part) {
$mimePart->addPart($part);
}
$mailMessage->setBody($mimePart);
} else {
$mailMessage->getHeaders()->addHeaderLine('Content-Type', $message->getContentType());
$mailMessage->setEncoding($message->getEncoding());
$mailMessage->setBody($message->getFilledBody());
}
return $mailMessage;
}
示例7: createService
public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('config');
if ($config instanceof Traversable) {
$config = ArrayUtils::iteratorToArray($config);
}
$config = $config['phly_contact']['message'];
$message = new Message();
if (isset($config['to'])) {
$message->addTo($config['to']);
}
if (isset($config['from'])) {
$message->addFrom($config['from']);
}
if (isset($config['sender']) && isset($config['sender']['address'])) {
$address = $config['sender']['address'];
$name = isset($config['sender']['name']) ? $config['sender']['name'] : null;
$message->setSender($address, $name);
}
return $message;
}
示例8: send
/**
* @param Message $message
* @param null $transport
* @return mixed
*/
public function send(Message $message, $transport = null)
{
if (!$message->getSender()) {
$sender = $transport ? $transport : 'default';
$emailAddress = $this->getOption('addressList')[$sender];
$message->setSender($emailAddress['address'], $emailAddress['name']);
}
return $this->getMailTransport($transport)->send($message);
}
示例9: getMessage
/**
* @param string $tpl
* @param array $data
* @return Message
*/
public function getMessage($tpl, array $data)
{
$mail = new Message();
$mail->setEncoding('UTF-8');
if (isset($data['encoding'])) {
$mail->setEncoding($data['encoding']);
}
if (isset($data['from_address'])) {
if (isset($data['from_name'])) {
$mail->setFrom($data['from_address'], $data['from_name']);
} else {
$mail->setFrom($data['from_address']);
}
}
if (isset($data['to'])) {
if (isset($data['to_name'])) {
$mail->setTo($data['to'], $data['to_name']);
} else {
$mail->setTo($data['to']);
}
}
if (isset($data['cc'])) {
$mail->setCc($data['cc']);
}
if (isset($data['bcc'])) {
$mail->setBcc($data['bcc']);
}
if (isset($data['subject'])) {
$mail->setSubject($data['subject']);
}
if (isset($data['sender'])) {
$mail->setSender($data['sender']);
}
if (isset($data['replyTo'])) {
$mail->setReplyTo($data['replyTo']);
}
$content = $this->renderMail($tpl, $data);
$mail->setBody($content);
$mail->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=UTF-8')->addHeaderLine('Content-Transfer-Encoding', '8bit');
return $mail;
}
示例10: message
/**
* Create a mail message
*
* @param string $subject
* @param string $body
* @param string $type
* @return MailHandler\Message
*/
public function message($subject = null, $body = null, $type = null)
{
$message = new MailHandler\Message();
$sender = array('mail' => Pi::config('adminmail'), 'name' => Pi::config('adminname') ?: null);
if ($sender['mail']) {
$message->setSender($sender['mail'], $sender['name']);
$message->setFrom($sender['mail'], $sender['name']);
}
$encoding = Pi::config('mail_encoding');
if ($encoding) {
$message->setEncoding($encoding);
}
if ($subject) {
$message->setSubject($subject);
}
if ($body) {
if ($type) {
$part = $this->mimePart($body, $type);
$body = new Mime\Message();
$body->addPart($part);
}
$message->setBody($body);
}
return $message;
}
示例11: send
public function send($id, $service = 'Email')
{
$this->getServiceEvent()->setEntityId($id)->setEntityClass('Lead\\Entity\\Lead')->setDescription('Email Sent (' . $service . ')')->setResult('');
if (!$this->checkAuth()) {
return $this->respondError(new \Exception('Insufficient User Authorization.', 401));
}
$options = $this->getOptions($id, $service);
$smtp_options = false;
if ($options) {
$fields = ['address_from' => null, 'address_to' => null, 'subject' => null];
foreach ($options as $scope => $settings) {
foreach ($settings as $option => $value) {
if ($value) {
switch ($option) {
case 'address_to':
switch ($scope) {
case 'global':
break;
case 'local':
$fields[$option] = $value;
break;
}
break;
case 'smtp':
switch ($scope) {
case 'global':
$smtp_options = $value;
break;
}
break;
default:
switch ($scope) {
case 'global':
if (!isset($fields[$option])) {
$fields[$option] = is_array($value) ? end($value) : $value;
}
break;
case 'local':
$fields[$option] = is_array($value) ? end($value) : $value;
break;
}
break;
}
}
}
}
$address_from = $address_to = $subject = $html = $text = null;
extract($fields);
if (isset($address_from, $address_to, $subject)) {
$data = $this->getData($id);
$parts = [];
if ($data) {
extract($data);
$config = $this->getServiceLocator()->get('Config');
$siteTitle = $config['site']['title'];
$body = new Mime\Message();
if (isset($text)) {
$parts['text'] = new Mime\Part($text);
$parts['text']->type = "text/plain";
}
if (isset($html)) {
$parts['html'] = new Mime\Part($html);
$parts['html']->type = "text/html";
}
$message = new Mail\Message();
switch ($service) {
case 'Email':
default:
$body->setParts($parts);
$message->setBody($body);
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
break;
case 'WebWorks':
$body = isset($text) ? $text : '';
$message->setBody($body);
break;
}
if (is_array($address_to)) {
$address_to = array_map('strtolower', $address_to);
} elseif (is_string($address_to)) {
$address_to = strtolower($address_to);
}
if (is_array($address_from)) {
$address_from = array_map('strtolower', $address_from);
} elseif (is_string($address_from)) {
$address_from = strtolower($address_from);
}
$message->setFrom($address_from);
$message->addTo($address_to);
$message->setSender($address_from, $siteTitle);
$message->setSubject($subject);
$message->setEncoding("UTF-8");
if ($smtp_options) {
$transport = new Mail\Transport\Smtp();
$_auth = new Mail\Transport\SmtpOptions(array('name' => $smtp_options['server'], 'host' => $smtp_options['server'], 'port' => $smtp_options['port'], 'connection_class' => 'login', 'connection_config' => array('username' => $smtp_options['username'], 'password' => $smtp_options['password'], 'ssl' => 'tls')));
$transport->setOptions($_auth);
try {
$transport->send($message);
} catch (\Exception $e) {
return $this->respondError(new \Exception($e->getMessage(), $e->getCode()));
//.........这里部分代码省略.........