zizhost
Email

Sending email from PHP

Server-side mail is disabled, so here is how to send via Mailgun or another provider.


Server-side mail is disabled

To keep the network off email blacklists, the local mail() function and direct SMTP from PHP on the hosting servers are disabled on the free tier. Attempting mail() will fail.

The right way: use an external provider

Sign up for a transactional mail provider and send through their API or SMTP relay. The popular options all have a free tier that covers a personal site:

Example with Mailgun (HTTP API)

Get a domain on Mailgun and verify it. This needs DNS access, so use your own domain pointed at zizhost; the free *.zizbe.com subdomain cannot be authenticated for outbound mail. Then:

<?php
function send_mail(string $to, string $subject, string $body): bool
{
    $domain = 'mg.example.com';                 // your verified Mailgun domain
    $apiKey = require __DIR__ . '/secrets.php'; // file outside public_html

    $ch = curl_init("https://api.mailgun.net/v3/{$domain}/messages");
    curl_setopt_array($ch, [
        CURLOPT_USERPWD        => 'api:' . $apiKey,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => [
            'from'    => '[email protected]',
            'to'      => $to,
            'subject' => $subject,
            'text'    => $body,
        ],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 10,
    ]);
    $res  = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $code === 200;
}

Example with SMTP (PHPMailer)

If you prefer SMTP, drop the small PHPMailer library into your project (upload via the file manager) and configure it with your provider’s SMTP credentials. Use TLS on port 587.

Why this is the right answer

  • Email reputation: shared free hosts get blacklisted regularly. A dedicated provider keeps your reach intact.
  • Authentication: SPF, DKIM, DMARC are handled by the provider once you verify your domain.
  • Visibility: providers give you delivery logs, bounce handling, and webhooks.

What about receiving mail?

Receiving mailboxes (e.g. [email protected]) work normally through the hosting panel’s Mail Accounts section when you bring your own domain. Outbound sending from PHP is still the part you’ll want to delegate to a provider.