Tutorial

Send Email with PHP (Laravel) via SMTP

PHPMailer for a plain script, or a Laravel Mailable — both over the same relay.

By the Sendcorex team·Updated Sep 21, 2026·8 min read

Option 1: PHPMailer

composer require phpmailer/phpmailer
use PHPMailer\PHPMailer\PHPMailer;

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.sendcorex.com';
$mail->SMTPAuth = true;
$mail->Username = getenv('SENDCOREX_API_KEY');
$mail->Password = getenv('SENDCOREX_API_KEY');
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->setFrom('hello@yourdomain.com', 'Your App');
$mail->addAddress('customer@example.com');
$mail->isHTML(true);
$mail->Subject = 'Welcome!';
$mail->Body = '<h1>You are in.</h1>';

$mail->send();

Option 2: Laravel Mailable

Set the relay in .env:

MAIL_MAILER=smtp
MAIL_HOST=smtp.sendcorex.com
MAIL_PORT=587
MAIL_USERNAME=your_api_key_here
MAIL_PASSWORD=your_api_key_here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello@yourdomain.com
MAIL_FROM_NAME="Your App"

Then generate and send a Mailable:

php artisan make:mail WelcomeMail

Mail::to('customer@example.com')->send(new WelcomeMail());

Common errors

SymptomFix
SMTP connect() failedCheck the host, port and that outbound 587 isn't blocked by your web host.
Queued mail never sendsConfirm php artisan queue:work is running if QUEUE_CONNECTION isn't sync.

Send your first email in minutes

Create a free account, verify your domain and paste in the code above.

No credit card required