1. Go to this page and download the library: Download kisphp/simple-mail 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/ */
kisphp / simple-mail example snippets
namespace Demo;
use Kisphp\Mail\MailConfigInterface;
class DemoMailConfig implements MailConfigInterface
{
public function getHost()
{
return 'ssl://smtp.gmail.com';
}
public function getPort()
{
return 465;
}
public function getSenderUsername()
{
return '[email protected]';
}
public function getSenderPassword()
{
return 'your account password';
}
public function getMailEncryptionType()
{
return null;
}
public function getFromEmail()
{
return '[email protected]';
}
public function getFromName()
{
return 'My website';
}
}
class DemoMailerFactory extends AbstractMailerFactory
{
/**
* @return DemoMailConfig
*/
public function createMailConfig()
{
return new DemoMailConfig();
}
}
$messenger = DemoMailerFactory::createMailer();
// recipients
$recipients = [
'[email protected]' => 'User name 1',
'[email protected]' => 'User name 2',
];
$subject = 'Testing mail';
$htmlMessage = 'this is my <b>message</b> for you';
// compose email
$messenger->createMailMessage($recipients, $subject, $htmlMessage);
// send the email and get the number of how many emails were sent
$emailsSent = $messenger->send();
use Kisphp\Mail\Messenger;
class ProjectMessenger extends Messenger
{
/**
* @return $this
*/
protected function createMailTransport()
{
$this->transport = \Swift_MailTransport::newInstance();
return $this;
}
}
class DemoMailerFactory extends AbstractMailerFactory
{
// createMailConfig method here
/**
* @param MailConfigInterface $config
*
* @return MessengerInterface
*/
public function createMessenger(MailConfigInterface $config)
{
return new ProjectMessenger($config);
}
}
// and load this class in your project
$messenger = new ProjectMessenger($config);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.