Produce, send and read mails using PHP + IMAP & SMTP.
This example shows how to send a text mail using chainability.
\CeusMedia\Mail\Transport\SMTP::getInstance("example.com", 587)
->setAuth("[email protected]", "my_password")
->send(\CeusMedia\Mail\Message::getInstance()
->setSender("[email protected]", "John Doe")
->addRecipient("[email protected]", "Mike Foo")
->setSubject("This is just a test")
->addText("Test Message...")
);
use \CeusMedia\Mail\Message;
use \CeusMedia\Mail\Transport\SMTP;
$message = new Message();
$message->setSender("[email protected]", "John Doe");
$message->addRecipient("[email protected]", "Mike Foo");
$message->addRecipient("[email protected]", NULL, 'cc');
$message->addRecipient("[email protected]", NULL, 'bcc' );
$message->setSubject("This is just a test");
$message->addText("Test Message...");
$message->addHTML('<h2><img src="CID:logo"/><br>Test Message</h2>');
$message->addInlineImage("logo", "logo.png");
$message->addFile("readme.md");
$transport = new SMTP("example.com", 587);
$transport->setUsername("[email protected]");
$transport->setPassword("my_password");
$transport->setVerbose(TRUE);
$transport->send( $message );
Sending a mail should be as easy as possible. This is an outlook how the interface could look like in future.
Attention: This is pseudo code. The used classes are not implemented yet.
use \CeusMedia\Mail\Client;
Client::getInstance("This is just a test")
->from("[email protected]", "John Doe")
->to("[email protected]", "Mike Foo")
->bcc("[email protected]")
->text("Test Message...")
->auth("my_password")
->port(587),
->error("handleMailException")
->send();
function handleMailException( $e ){
// ...
}
Google tried to protect its SMTP access by several measures. If you are having problems sending mails using Google SMTP, tried these steps: