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
Konfigurieren Sie das 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"
Erzeugen und senden Sie dann ein Mailable:
php artisan make:mail WelcomeMail
Mail::to('customer@example.com')->send(new WelcomeMail());
Häufige Fehler
| Symptom | Lösung |
|---|---|
SMTP connect() failed | Prüfen Sie Host, Port und ob Ihr Webhoster den ausgehenden Port 587 blockiert. |
| Mails in der Warteschlange werden nie gesendet | Prüfen Sie, ob php artisan queue:work läuft, wenn QUEUE_CONNECTION nicht sync ist. |