Skip to content

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, port 587 with STARTTLS (or 465 with 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-KEY header. 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_PASS and MAILIQO_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) ​

bash
npm install nodemailer
js
import 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) ​

bash
composer require phpmailer/phpmailer
php
<?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:

ini
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.

php
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 ​

bash
composer require symfony/mailer

In .env.local:

ini
MAILER_DSN=smtp://USERNAME:[email protected]:587?require_tls=true

If the username or password contain special characters, URL-encode them. For port 465, use smtps://USERNAME:[email protected]:465.

php
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) ​

python
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.

bash
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."
  }'
js
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
<?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);
php
// 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();
php
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);
    }
}
python
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 ​

HTTPWhat to do
200Queued. With status = warning, some recipients were rejected: check rejected_recipients.
400Fix the request: error.code says why. See Errors.
401Check the API key.
429Sending limit reached (code 1421). Wait the seconds in the Retry-After header and send again.
500Try 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:

LibraryWhere
Nodemailererr.responseCode and err.response
PHPMailer$mail->ErrorInfo
Laravel and Symfony MailerThe message of the TransportException
Pythonsmtp_code and smtp_error of smtplib.SMTPResponseException and its subclasses

Sources ​

Checked on 2 November 2026:


Next steps ​

Built with VitePress