Master da Web
SMTP guide

Send email with PHP over SMTP with PHPMailer, the right way

PHP's mail() function hands the message to the local mail server, without authenticating your domain and without telling you what happened. With PHPMailer and authenticated SMTP, every message leaves with DKIM, SPF and DMARC aligned and shows up in the panel's logs.

The sandbox is free for everyone. Already run a cloud service with us? The free plan is yours too.

send.php

<?phpuse PHPMailer\PHPMailer\PHPMailer;require 'vendor/autoload.php'; $mail = new PHPMailer(true); // throws if it fails$mail->isSMTP();$mail->Host = getenv('SMTP_HOST');$mail->Port = 587;$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;$mail->SMTPAuth = true;$mail->Username = 'apikey';$mail->Password = getenv('SMTP_PASSWORD');$mail->CharSet = 'UTF-8'; $mail->setFrom('orders@yourdomain.com', 'My Store');$mail->addAddress('ana@example.com', 'Ana');$mail->Subject = 'Order confirmed';$mail->isHTML(true);$mail->Body = '<p>Hi Ana! We received your order.</p>';$mail->AltBody = 'Hi Ana! We received your order.';$mail->send();

SMTP_HOST and SMTP_PASSWORD are environment variables holding the panel's host and your sending key. Always send the plain text (AltBody) along with the HTML.

PHP

Step by step: SMTP in PHP

From a verified domain to the first delivered email, with the result of each send in the panel.

  1. 1

    Verify your domain

    Add the domain in the panel, under Email & SMTP, and publish the DNS records it shows.

  2. 2

    Create a sending key

    The key is the SMTP password. Keep it in an environment variable, out of the code.

  3. 3

    Install PHPMailer

    With Composer: composer require phpmailer/phpmailer.

  4. 4

    Send and follow up

    Run the example and see the delivery in the panel's Activity, with the receiving server's answer.

Beyond SMTP

What you get by sending with Master da Web

Delivery under your domain

DKIM with your domain's key, aligned SPF and DMARC: what Gmail, Yahoo and Microsoft check before they accept.

Per-recipient logs

Delivered, deferred, bounced or marked as spam, with the receiving server's full answer.

Webhooks and suppressions

Signed events in your system, and bounces and complaints taken off the list by themselves.

Free sandbox

A sandbox key captures messages so you can test without delivering anything to anyone.

What it costs

Plans from R$29.00 a month, with 10,000 emails included. If you run a cloud service with us, you start on the free plan, with 3,000 emails a month. The sandbox is free for everyone.

See plans and prices
Discover the SMTP & Email API
FAQ

Questions about SMTP in PHP

What comes up most while setting it up.

Set up SMTP in PHP today

Create your account, verify your domain and start testing today.