Skip to main content

Connection Strings

Connection strings define how to connect to mail services. They follow a URI format:

scheme://username:password@host:port

URI Components

PartDescription
schemeThe email scheme: smtp, ssl, tls, sendmail, mailgun, ses, fakesender
usernameThe username for authentication
passwordThe password for authentication
hostThe SMTP host or service endpoint
portThe SMTP port

Available Schemes

SchemeDescriptionURI PatternWrapper Class
smtpSMTP over insecure connectionsmtp://username:password@host:25PHPMailerWrapper
tlsSMTP over secure TLS connectiontls://username:password@host:587PHPMailerWrapper
sslSMTP over secure SSL connectionssl://username:password@host:465PHPMailerWrapper
sendmailPHP's built-in mail() functionsendmail://localhostSendMailWrapper
mailgunMailgun APImailgun://YOUR_API_KEY@YOUR_DOMAINMailgunApiWrapper
sesAmazon SES APIses://ACCESS_KEY_ID:SECRET_KEY@REGIONAmazonSesWrapper
fakesenderTesting (does nothing)fakesender://localhostFakeSenderWrapper

Examples

SMTP with TLS

$mailer = \ByJG\Mail\MailerFactory::create(
'tls://username:[email protected]:587'
);

Gmail

$mailer = \ByJG\Mail\MailerFactory::create(
'tls://[email protected]:[email protected]:587'
);
info

Gmail requires you to enable "Allow less secure apps" in your Google account settings. Visit https://www.google.com/settings/security/lesssecureapps to enable this option.

Changes may take up to an hour to take effect.

Mailgun API

$mailer = \ByJG\Mail\MailerFactory::create(
'mailgun://YOUR_API_KEY@YOUR_DOMAIN'
);

You can specify the region using a query parameter:

// EU region
$mailer = \ByJG\Mail\MailerFactory::create(
'mailgun://YOUR_API_KEY@YOUR_DOMAIN?region=eu'
);

Valid regions: us (default), eu

Amazon SES

$mailer = \ByJG\Mail\MailerFactory::create(
'ses://ACCESS_KEY_ID:SECRET_KEY@us-east-1'
);

The region can be any valid AWS region (e.g., us-east-1, eu-west-1, etc.).

SendMail (PHP mail() function)

$mailer = \ByJG\Mail\MailerFactory::create(
'sendmail://localhost'
);
warning

You need to configure your email relay in php.ini for SendMail to work properly.

FakeSender (Testing)

$mailer = \ByJG\Mail\MailerFactory::create(
'fakesender://localhost'
);

The FakeSender wrapper does nothing and always returns success. It's useful for testing without actually sending emails.