Code examples
Examples for sending through Mailiqo from the most common languages and frameworks, over SMTP or with the API.
Versions checked on 2 November 2026
Nodemailer 10.3.1, PHPMailer 7.1.1, Laravel 13 (also valid for 11 and 12), Symfony 8.1 and the Python 3 standard library. Based on each project's official documentation (links at the end).
Before you start
- SMTP: host
smtpmq.mailiqo.com, port587with STARTTLS (or465with implicit TLS), and the domain's SMTP username and password, from Email → Domains. - API: an API key from Settings → API & integrations, sent in the
X-API-KEYheader. See Authentication. - The sender must be an address on the verified domain.
- Keep credentials out of the code. The examples read them from the environment variables
MAILIQO_SMTP_USER,MAILIQO_SMTP_PASSandMAILIQO_API_KEY.
SMTP is the quickest way to connect an application that already sends email. The API returns the result per recipient and a uuid to follow the delivery. See SMTP overview and Email sending API.
SMTP
Node.js (Nodemailer)
npm install nodemailerimport nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'smtpmq.mailiqo.com',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: process.env.MAILIQO_SMTP_USER,
pass: process.env.MAILIQO_SMTP_PASS,
},
});
const info = await transporter.sendMail({
from: '"Your Store" <[email protected]>',
to: '[email protected]',
subject: 'Your order has shipped',
text: 'Your order is on its way.',
html: '<p>Your order is on its way.</p>',
});
console.log(info.messageId);secure: false with requireTLS: true makes Nodemailer upgrade the connection with STARTTLS and fail if it can't. For port 465, use port: 465 and secure: true.
PHP (PHPMailer)
composer require phpmailer/phpmailer<?php
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtpmq.mailiqo.com';
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = getenv('MAILIQO_SMTP_USER');
$mail->Password = getenv('MAILIQO_SMTP_PASS');
$mail->CharSet = PHPMailer::CHARSET_UTF8;
$mail->setFrom('[email protected]', 'Your Store');
$mail->addAddress('[email protected]');
$mail->isHTML(true);
$mail->Subject = 'Your order has shipped';
$mail->Body = '<p>Your order is on its way.</p>';
$mail->AltBody = 'Your order is on its way.';
$mail->send();
} catch (Exception $e) {
echo $mail->ErrorInfo;
}For port 465, use $mail->Port = 465 and PHPMailer::ENCRYPTION_SMTPS.
Laravel
In .env:
MAIL_MAILER=smtp
MAIL_SCHEME=smtp
MAIL_HOST=smtpmq.mailiqo.com
MAIL_PORT=587
MAIL_USERNAME=your-smtp-username
MAIL_PASSWORD=your-smtp-password
MAIL_FROM_ADDRESS[email protected]
MAIL_FROM_NAME="Your Store"With MAIL_SCHEME=smtp and port 587, Laravel upgrades the connection with STARTTLS. For port 465, use MAIL_PORT=465 and MAIL_SCHEME=smtps. On Laravel 10, use MAIL_ENCRYPTION=tls instead of MAIL_SCHEME.
use Illuminate\Support\Facades\Mail;
Mail::raw('Your order is on its way.', function ($message) {
$message->to('[email protected]')->subject('Your order has shipped');
});In a real application you'd normally send a Mailable; the SMTP configuration is the same. If the configuration is cached, run php artisan config:cache after changing .env.
Symfony Mailer
composer require symfony/mailerIn .env.local:
MAILER_DSN=smtp://USERNAME:[email protected]:587?require_tls=trueIf the username or password contain special characters, URL-encode them. For port 465, use smtps://USERNAME:[email protected]:465.
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
final class OrderMailer
{
public function __construct(private MailerInterface $mailer)
{
}
public function sendShipped(string $to): void
{
$email = (new Email())
->from('[email protected]')
->to($to)
->subject('Your order has shipped')
->text('Your order is on its way.')
->html('<p>Your order is on its way.</p>');
$this->mailer->send($email);
}
}If your application uses Messenger, Symfony queues the email by default and the worker sends it, so SMTP errors show up in the worker.
Python (smtplib)
import os
import smtplib
import ssl
from email.message import EmailMessage
msg = EmailMessage()
msg['From'] = 'Your Store <[email protected]>'
msg['To'] = '[email protected]'
msg['Subject'] = 'Your order has shipped'
msg.set_content('Your order is on its way.')
msg.add_alternative('<p>Your order is on its way.</p>', subtype='html')
context = ssl.create_default_context()
with smtplib.SMTP('smtpmq.mailiqo.com', 587, timeout=30) as server:
server.starttls(context=context)
server.login(os.environ['MAILIQO_SMTP_USER'], os.environ['MAILIQO_SMTP_PASS'])
server.send_message(msg)For port 465, use smtplib.SMTP_SSL('smtpmq.mailiqo.com', 465, context=context) and remove the starttls() call.
API
POST https://api.mailiqo.com/v1/mailing/send with the email in JSON. All fields are described in POST /mailing/send.
curl -X POST https://api.mailiqo.com/v1/mailing/send \
-H "X-API-KEY: $MAILIQO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Your order has shipped",
"body_html": "<p>Your order is on its way.</p>",
"body_txt": "Your order is on its way."
}'const response = await fetch('https://api.mailiqo.com/v1/mailing/send', {
method: 'POST',
headers: {
'X-API-KEY': process.env.MAILIQO_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
from: '[email protected]',
to: '[email protected]',
subject: 'Your order has shipped',
body_html: '<p>Your order is on its way.</p>',
body_txt: 'Your order is on its way.',
}),
});
const result = await response.json();
console.log(response.status, result.status);<?php
$payload = [
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Your order has shipped',
'body_html' => '<p>Your order is on its way.</p>',
'body_txt' => 'Your order is on its way.',
];
$ch = curl_init('https://api.mailiqo.com/v1/mailing/send');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-KEY: ' . getenv('MAILIQO_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$result = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);// config/services.php: 'mailiqo' => ['key' => env('MAILIQO_API_KEY')],
use Illuminate\Support\Facades\Http;
$response = Http::withHeaders([
'X-API-KEY' => config('services.mailiqo.key'),
])->post('https://api.mailiqo.com/v1/mailing/send', [
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Your order has shipped',
'body_html' => '<p>Your order is on its way.</p>',
'body_txt' => 'Your order is on its way.',
]);
$result = $response->json();use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class MailiqoClient
{
public function __construct(
private HttpClientInterface $httpClient,
#[Autowire(env: 'MAILIQO_API_KEY')] private string $apiKey,
) {
}
public function send(array $email): array
{
$response = $this->httpClient->request('POST', 'https://api.mailiqo.com/v1/mailing/send', [
'headers' => ['X-API-KEY' => $this->apiKey],
'json' => $email,
]);
return $response->toArray(false);
}
}import os
import requests
response = requests.post(
'https://api.mailiqo.com/v1/mailing/send',
headers={'X-API-KEY': os.environ['MAILIQO_API_KEY']},
json={
'from': '[email protected]',
'to': '[email protected]',
'subject': 'Your order has shipped',
'body_html': '<p>Your order is on its way.</p>',
'body_txt': 'Your order is on its way.',
},
timeout=30,
)
result = response.json()A 200 means the email was queued: check status and, if it's warning, the rejected_recipients list. See Email sending API.
Errors and sending limits
API
| HTTP | What to do |
|---|---|
200 | Queued. With status = warning, some recipients were rejected: check rejected_recipients. |
400 | Fix the request: error.code says why. See Errors. |
401 | Check the API key. |
429 | Sending limit reached (code 1421). Wait the seconds in the Retry-After header and send again. |
500 | Try again later. |
A request rejected with 429 isn't queued: your application has to send it again once the Retry-After time has passed. See Sending limits.
SMTP
Replies starting with 4 are temporary, such as 451 4.7.1 when the sending limit is reached: the server didn't accept the message, so send it again later. Replies starting with 5 are permanent: sending the same message again fails until you fix the cause. See SMTP errors.
Where each library gives you the server's reply:
| Library | Where |
|---|---|
| Nodemailer | err.responseCode and err.response |
| PHPMailer | $mail->ErrorInfo |
| Laravel and Symfony Mailer | The message of the TransportException |
| Python | smtp_code and smtp_error of smtplib.SMTPResponseException and its subclasses |
Sources
Checked on 2 November 2026:
- Nodemailer — SMTP transport — Nodemailer documentation
- PHPMailer — official repository
- Laravel — Mail — Laravel documentation
- Symfony — Sending emails with Mailer — Symfony documentation
- smtplib — Python documentation
Next steps
- Email sending API → /api-reference/sending
- SMTP errors → /smtp/errors
