-
Notifications
You must be signed in to change notification settings - Fork 159
Mail Extension
Dmitriy Zayceff edited this page Apr 24, 2015
·
7 revisions
- Since: 0.6.3
- Dependency:
org.develnext:jphp-mail-ext
- API: http://jphp-docs.readthedocs.org/en/latest/api_en/php/mail/
A simple extension for sending mail via an smtp server.
Sending email via Gmail account.
use php\mail\Email;
use php\mail\EmailBackend;
// Create email server backend configuration.
$backend = new EmailBackend();
// set username and password of gmail account
$backend->setAuthentication('[email protected]', 'password');
// host name of gmail smtp server
$backend->hostName = 'smtp.googlemail.com';
$backend->smtpPort = 465;
$backend->sslOnConnect = true;
$email = new Email();
$email->setSubject('Hello!');
$email->setFrom('[email protected]', 'JPHP Compiler');
$email->setTo(['[email protected]', '[email protected]']);
// Set html text
$email->setHtmlMessage('<b>Foobar</b>');
// Set simple text
$email->setTextMessage('Foobar');
// Add attachment using file, also you can use php\io\Stream objects.
$email->attach('path/to/file', 'image/jpeg', 'My Picture');
try {
$messageId = $email->send($backend);
} catch (Exception $e) {
// error ...
}
JPHP Group 2015