Prompt

How do I send emails from a PHP application?

Technology / Api platforms1 observationLast seen Sep 23, 2026

Latest observation

Sep 23, 2026OpenAI APIWeb search: off

The common ways to send email from a PHP app are:

1) Use a mail library over SMTP

This is the most reliable approach. The most popular library is PHPMailer.

Install with Composer

composer require phpmailer/phpmailer

Example with SMTP

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    $mail->isSMTP();
    $mail->Host = 'smtp.example.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'your_username';
    $mail->Password = 'your_password';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // or PHPMailer::ENCRYPTION_SMTPS
    $mail->Port = 587;

    $mail->setFrom('from@example.com', 'My App');
    $mail->addAddress('to@example.com', 'Recipient Name');

    $mail->isHTML(true);
    $mail->Subject = 'Hello from PHP';
    $mail->Body    = '<p>This is a test email.</p>';
    $mail->AltBody = 'This is a test email.';

    $mail->send();
    echo 'Message sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

2) Use PHP’s built-in mail() function

This is simpler, but less reliable and often not recommended for production.

$to = 'user@example.com';
$subject = 'Test email';
$message = 'Hello from PHP';
$headers = 'From: webmaster@example.com' . "\r\n" .
           'Reply-To: webmaster@example.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

Downsides of mail()

  • Depends on server mail configuration
  • Often ends up in spam
  • Harder to debug
  • No built-in authentication/TLS handling

3) Use a transactional email service

For apps, this is often best:

  • SendGrid
  • Mailgun
  • Amazon SES
  • Postmark

These services usually provide:

  • Better deliverability
  • SMTP or HTTP APIs
  • Bounce/complaint tracking
  • Templates and logs

Best practice

For most applications:

  • Use PHPMailer or Symfony Mailer
  • Send via SMTP
  • Use a real email provider
  • Set up SPF, DKIM, and DMARC for your domain

If you want, I can show you:

  1. a PHPMailer example with Gmail/SMTP,
  2. how to send HTML emails with attachments, or
  3. how to use Symfony Mailer instead.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as Circuit. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.