1. Go to this page and download the library: Download byjg/mailwrapper 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/ */
byjg / mailwrapper example snippets
// Create the email envelope
$envelope = new ByJG\Mail\Envelope();
$envelope->setFrom('[email protected]', 'John Doe');
$envelope->addTo('[email protected]');
$envelope->setSubject('Email Subject');
$envelope->setBody('html text body');
// Register the available class
\ByJG\Mail\MailerFactory::registerMailer(\ByJG\Mail\Wrapper\PHPMailerWrapper::class);
\ByJG\Mail\MailerFactory::registerMailer(\ByJG\Mail\Wrapper\MailgunApiWrapper::class);
// Create the proper mailer based on the scheme
// In the example below will find the "mailgun" scheme
$mailer = \ByJG\Mail\MailerFactory::create('mailgun://api:YOUR_API_KEY@YOUR_DOMAIN');
// Send the email:
$mailer->send($envelope);
$mailer = new \ByJG\Mail\Wrapper\MailgunApiWrapper(
new \ByJG\Util\Uri(
'mailgun://your_api_key@YOUR_DOMAIN'
)
);
// Send the email:
$mailer->send($envelope);
class MyWrapper extends \ByJG\Mail\Wrapper\BaseWrapper
{
public static function schema()
{
return ['mywrapper'];
}
public function send(Envelope $envelope)
{
// Do how to send the email using your library
}
// You can create your own validation methods.
public function validate(Envelope $envelope)
{
parent::validate($envelope);
}
}