PHP code example of mailpace / mailpace-swiftmailer
1. Go to this page and download the library: Download mailpace/mailpace-swiftmailer 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/ */
mailpace / mailpace-swiftmailer example snippets
nsport = new MailpaceSwiftmailerTransport(env('OHMYSMTP_API_TOKEN'));
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message('A transactional email from MailPace!'))
->setFrom(['[email protected]' => 'Your Name'])
->setTo(['[email protected]'])
->setBody('<h1>HTML content</h1>', 'text/html')
->addPart('Text Body','text/plain');
// Attachments
$data = 'Raw Attachment Data';
$attachment = new Swift_Attachment($data, 'attachment.txt', 'text/plain');
$message->attach($attachment);
// Email Tags
$headers = $message->getHeaders();
$headers->addTextHeader('MailPace-Tag', 'tag-1');
$headers->addTextHeader('MailPace-Tag', 'tag with spaces');
$mailer->send($message);
namespace App\Providers;
use Illuminate\Mail\MailManager;
use Illuminate\Mail\MailServiceProvider;
use Mailpace\MailpaceSwiftmailer\MailpaceSwiftmailerTransport;
class MailpaceServiceProvider extends MailServiceProvider
{
protected function registerIlluminateMailer()
{
$this->app->singleton('mail.manager', function ($app) {
$manager = new MailManager($app);
$this->registerOhMySmtpTransport($manager);
return $manager;
});
}
protected function registerOhMySmtpTransport(MailManager $manager) {
$manager->extend('mailpace', function ($config) {
if (! isset($config['apiToken'])) {
$config = $this->app['config']->get('services.mailpace', []);
}
return new MailpaceSwiftmailerTransport($config['apiToken']);
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.