Can I configure WordPress to use postfix without a plugin?

I am developing a WordPress site on a vagrant box and have installed postfix in order to test email notifications.

At this guest OS (Ubuntu) level, I am able to end a test email:

echo "Test mail from postfix" | mail -s "Test Postfix" [email protected]

This works and I receive the email. As far as I know postfix uses the sendmail binary and so I would expect WordPress to send emails successfully.

However, my contact form notifications are not being received. Is there a way to check/debug email sending in WordPress or verify which mail function it is using?

UPDATE

So after a bit of digging I discovered that wp_mail() uses PHPMailer. If I debug the wp_mail() function using this test script I see that PHPMailer is throwing an exception:

Could not instantiate mail function.

// Set $to as the email you want to send the test to
$to = "[email protected]";

// No need to make changes below this line

// Email subject and body text
$subject="wp_mail function test";
$message="This is a test of the wp_mail function: wp_mail is working";
$headers[] = 'From: Me Myself <[email protected]>';

// Load WP components, no themes
define('WP_USE_THEMES', false);
require('wp/wp-load.php');

// Call the wp_mail function, display message based on the result.
if( wp_mail( $to, $subject, $message, $headers ) ) {
    // the message was sent...
    echo 'The test message was sent. Check your email inbox.';
} else {
    // the message was not sent...
    echo 'The message was not sent!';
};

1 Answer
1

WordPress uses the wp_mail() function to send mail. It says on the Codex article there that:

For this function to work, the settings SMTP and smtp_port (default: 25) need to be set in your php.ini file.

Also be sure to check that your contact form is sending the required parameters to the wp_mail() function. The required parameters are included on the page in the link above.

Leave a Comment