1. Go to this page and download the library: Download popphp/pop-mime library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
popphp / pop-mime example snippets
use Pop\Mime\Message;
use Pop\Mime\Part\Body;
$message = new Message();
$message->addHeaders([
'Subject' => 'Hello World',
'To' => '[email protected]',
'Date' => date('m/d/Y g:i A')
]);
$body = new Body('Hello World!');
$message->setBody($body);
echo $message;
use Pop\Mime\Message;
use Pop\Mime\Part;
$message = new Message();
$message->addHeaders([
'Subject' => 'Hello World',
'To' => '[email protected]',
'Date' => date('m/d/Y g:i A')
]);
$message->setSubType('alternative');
$html = new Part();
$html->addHeader('Content-Type', 'text/html');
$html->setBody('<html><body><h1>This is the HTML message.</h1></body></html>');
$text = new Part();
$text->addHeader('Content-Type', 'text/plain');
$text->setBody('This is the text message.');
$message->addParts([$html, $text]);
echo $message;
use Pop\Mime\Message;
use Pop\Mime\Part;
$message = new Message();
$message->addHeaders([
'Subject' => 'Hello World',
'To' => '[email protected]',
'Date' => date('m/d/Y g:i A')
]);
$message->addParts([
Part::html('<html><body><h1>This is the HTML message.</h1></body></html>'),
Part::text('This is the text message.')
]);
$message->inferSubType();
echo $message;
use Pop\Mime\Message;
use Pop\Mime\Part;
$message = new Message();
$message->addHeaders([
'Subject' => 'Hello World',
'To' => '[email protected]',
'Date' => date('m/d/Y g:i A'),
'MIME-Version' => '1.0'
]);
$message->setSubType('mixed');
$html = new Part();
$html->addHeader('Content-Type', 'text/html');
$html->setBody('<html><body><h1>This is the HTML message.</h1></body></html>');
$text = new Part();
$text->addHeader('Content-Type', 'text/plain');
$text->setBody('This is the text message.');
$file = new Part();
$file->addHeader('Content-Type', 'application/pdf');
$file->addFile('test.pdf');
$message->addParts([$html, $text, $file]);
echo $message;
use Pop\Mime\Part\Body\Encoding;
$file = Part::attachment('test.pdf', null, 'attachment', Encoding::QUOTED_PRINTABLE);
use Pop\Mime\Part\Body;
$body = new Body('Hello World!', Encoding::QUOTED_PRINTABLE);
$header = new Header('Content-Type', 'text/html');
echo $header;
$header = new Header('Content-Type', 'text/html');
print_r($header->getValue()); // Returns an instance of Pop\Mime\Header\Value
use Pop\Mime\Part\Header;
$header = new Header('Content-Disposition');
$value = new Header\Value('attachment');
$value->addParameter('filename', 'filename.jpg');
$header->addValue($value);
echo $header;
$header = new Header('X-Multi-Header', ['value-1', 'value-2', 'value-3']);
$header = new Header('X-Multi-Header');
$header->addValue('value-1')
->addValue('value-2')
->addValue('value-3');
echo $header;
$value = $header->getValue(2);
use Pop\Mime\Part\Header\AddressList;
$list = AddressList::parse('"Doe, John" <[email protected]>, Jane Doe <[email protected]>');
foreach ($list->getAddresses() as $address) {
echo $address->getName() . ' <' . $address->getAddress() . ">\n";
}
echo $list->render();
use Pop\Mime\Message;
use Pop\Mime\Part\Header\Address;
use Pop\Mime\Part\Header\AddressList;
$list = new AddressList([
new Address('[email protected]', 'Doe, John'),
new Address('[email protected]', 'Jane Doe'),
]);
$message = new Message();
$message->addHeader('To', $list->render());
use Pop\Mime\Part\Header\Address;
$address = new Address('[email protected]', 'José García');
echo $address->render();
use Pop\Mime\Part\Header\EncodedWord;
echo EncodedWord::encode('José García'); // =?UTF-8?B?Sm9zw6kgR2FyY8OtYQ==?=
echo EncodedWord::decode('=?UTF-8?B?Sm9zw6kgR2FyY8OtYQ==?='); // José García
use Pop\Mime\Message;
$message = new Message();
$message->setMessageId();
echo $message->getHeader('Message-ID');
$message->setMessageId(null, 'example.com');
use Pop\Mime\Part;
$inlineImage = Part::attachment('logo.png');
$inlineImage->setContentId(null, 'example.com');