What are some common pitfalls when trying to send emails with PHP and Mercury?

One common pitfall when sending emails with PHP and Mercury is not properly configuring the email settings, such as the SMTP server, port, and authentication credentials. To solve this issue, make sure to double-check and accurately input the correct email settings in your PHP script.

// Set the SMTP server, port, and authentication credentials
$smtpServer = 'mail.example.com';
$smtpPort = 587;
$smtpUsername = 'your_username';
$smtpPassword = 'your_password';

// Set the email headers
$headers = 'From: sender@example.com' . "\r\n" .
           'Reply-To: sender@example.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

// Send the email
if (mail('recipient@example.com', 'Subject', 'Message', $headers, "-f sender@example.com", "-r sender@example.com", "-S $smtpServer:$smtpPort -au$smtpUsername -ap$smtpPassword")) {
    echo 'Email sent successfully.';
} else {
    echo 'Email sending failed.';
}