MailboxHeader example


    public function addMailboxListHeader(string $name, array $addresses)static
    {
        return $this->add(new MailboxListHeader($name, Address::createArray($addresses)));
    }

    /** * @return $this */
    public function addMailboxHeader(string $name, Address|string $address)static
    {
        return $this->add(new MailboxHeader($name, Address::create($address)));
    }

    /** * @return $this */
    public function addIdHeader(string $name, string|array $ids)static
    {
        return $this->add(new IdentificationHeader($name$ids));
    }

    /** * @return $this */
namespace Symfony\Component\Mime\Tests\Header;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\MailboxHeader;

class MailboxHeaderTest extends TestCase
{
    public function testConstructor()
    {
        $header = new MailboxHeader('Sender', $address = new Address('fabien@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
    }

    public function testAddress()
    {
        $header = new MailboxHeader('Sender', new Address('fabien@symfony.com'));
        $header->setBody($address = new Address('helene@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
        $header->setAddress($address = new Address('thomas@symfony.com'));
        

    public function addMailboxListHeader(string $name, array $addresses)static
    {
        return $this->add(new MailboxListHeader($name, Address::createArray($addresses)));
    }

    /** * @return $this */
    public function addMailboxHeader(string $name, Address|string $address)static
    {
        return $this->add(new MailboxHeader($name, Address::create($address)));
    }

    /** * @return $this */
    public function addIdHeader(string $name, string|array $ids)static
    {
        return $this->add(new IdentificationHeader($name$ids));
    }

    /** * @return $this */
'MIME-Version' => '1.0',
      'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
      'Content-Transfer-Encoding' => '8Bit',
      'X-Mailer' => 'Drupal',
    ];
    // To prevent email from looking like spam, the addresses in the Sender and     // Return-Path headers should have a domain authorized to use the     // originating SMTP server.     $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $site_mail;
    // Make sure the site-name is a RFC-2822 compliant 'display-name'.     if ($site_mail) {
      $mailbox = new MailboxHeader('From', new Address($site_mail$site_config->get('name') ?: ''));
      $headers['From'] = $mailbox->getBodyAsString();
    }
    if ($reply) {
      $headers['Reply-to'] = $reply;
    }
    $message['headers'] = $headers;

    // Build the email (get subject and body, allow additional headers) by     // invoking hook_mail() on this module.     $this->moduleHandler->invoke($module, 'mail', [$key, &$message$params]);

    
Home | Imprint | This part of the site doesn't use cookies.