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
| Symptom | Fix |
|---|---|
SMTP connect() failed | Check the host, port and that outbound 587 isn't blocked by your web host. |
| Queued mail never sends | Confirm php artisan queue:work is running if QUEUE_CONNECTION isn't sync. |