Can't send mail from WordPress forms

SYSTEM INFORMATION
OS type and version Debian Linux 11
Virtualmin version Version 7.7

As background, I run DNS, mail services and websites on different boxes. So I do not need incoming mail for domains I host on the box serving their websites.

It appears I’m unable to send form output from WordPress sites on my Virtualmin server. I seem to get all the typical notifications from the box, like when setting up virtual servers, when nightly backups are completed, etc. I am wondering if it is something really simple like a setting someplace. I thought about the firewall but then I don’t believe that would allow all the notifications from Virtualmin to be sent.

It’s like the PHP mail is going nowhere. I have checked the mail queue and nothing is in it waiting to be sent. There are no errors in either of the site’s php_log files.

Executing this addressed to myself works just fine from the command line:
echo "Subject: Test Mail" | /usr/sbin/sendmail -v your-email@example.com

Executing this shows nothing out of the ordinary numerous break-in attempts - but no errors I can see when trying to send anything out:
tail -f -n 50 /var/log/mail.log

Accessing this simply shows me that it failed - but does not give me any error indication at all:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$to = 'your-email@example.com';
$subject = 'Test Mail';
$message = 'Hello, this is a test email.';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully";
} else {
    echo "Email sending failed";
}
?>

I’m exercising caution since these are live sites.

It’s as though the outgoing messages just go into a black hole.

Thanks for any ideas!
Charles

1 Like

High in the search results I see something like ‘15 best Wordpress email plugins’. So, the question is how is YOUR Wordpress set to send email? It won’t show up in the system logs if it sends directly using its’ own script.

Can you post the relevant section of how you set it up?

From memory the php mail function requires an mta to be running, e.g postfix or sendmail, so if both are disabled i guess sending mail from a php app will fail. If this is the case just re enable postfix and configure it to reject all incoming mail

Hi, I generally never have had to set up WordPress to send email before Virtualmin. I have six other servers (on several versions of Debian and CentOS) with the same (different than Virtualmin) control panel on them handling a significant number of WordPress sites and can move WordPress sites back and forth between them seamlessly. I have never had to do anything to them (including adding any kind of plugins) to send mail from WordPress sites. So when this issue arose after ten sites were on Virtualmin the box it caught me completely off guard.

When ask about posting the relevant section of how I set it up I am not certain of what you are specifically asking about. The entire server? I just loaded Debian 11 and set up Virtualmin the standard way it does. Its only my second Virtualmin server so I’m not really good at it yet…

Both postfix and sendmail are operational on the box.

Thanks,
Charles

Just the section in WP you have to fill out.

We don’t know if it sends through your MTA or uses its’ own mail script.

That then indicates a problem with wordpress however the php code you posted should have left entries in the mail log

I didn’t fill out anything. I used the “script” in Virtualmin’s control panel to add WordPress to each site. Then I migrate the site using a clone of the site. In both cases (WordPress installs) I moved these sites from elsewhere - one from a different provider and the other created by us but previously on a different non-Virtualmin server.

Now that you have me thinking this through more, I should create another site on the server and add a contact form plugin and see if that behaves differently. The form functionality on the two sites I discovered this issue with are built into the theme (which has never given me an issue in thousands of other websites). This way I can rule out the theme.

That troubled me that no entries appeared in the mail log. But then, if it is never connecting at all with a mail transport then I think it makes sense there’d most likely be no log entry.

Being a php coder I hit this when a client did not have postfix configured correctly. That said, assuming you have turned off mail for domain in vmin I am unsure how postfix is then reconfigured it may be worth putting up a new domain with mail enabled and test that

it may be worth putting up a new domain with mail enabled and test that

I like that idea.

However, I do know that on my other servers, when DNS says email is elsewhere and the mail is inadvertently enabled locally on a domain, the server does not send that mail out, and mail (like form output) simply accumulates locally. Sort of the inverse of the problem I am experiencing here. We even have an entry on the site setup checklists to ensure it is turned off locally (LOL).

To send emails through Wordpress you will usually need a plugin.
(1-) Which version of Wordpress are you having trouble with?
(2-) Is it possible to show, through a screenshot, your plugin page?

the OP posted this

which didn’t work
this needs to be fixed before you start looking at wordpress as wordpress is a php app. I would guess most wordpress mail plugins depend on the php mail function and just wrap that up in a different way to appease a wordpress user

I guess I’m spoiled, as after 25 years and five plus thousand websites in the hosting and web development business I have never encountered needing/requiring plugins for WordPress sites to send email.

You don’t you need to fix the problem that is causing the php mail function to fail look at this

While that may or may not be true that just wrap that up in a different way to appease a WordPress user, I tried a plugin on one site because we needed form output to be able to be emailed out ASAP and it DID work (which was easier than moving the site to one of my other servers where no additional plugin is needed to send out emails).

I would not call myself a PHP coder. Only know for sure that I don’t know quite a bit. That said, there is little doubt in my mind that the connection between PHP and the mail transport isn’t functioning. Apparently the plugin I used (the band aid I should say) is able to bridge that gap with one of the mail transports.

I’ve been through this for a while.
THAT’S WHY I ASKED YOU TO ENTER YOUR VERSION OF WORDPRESS.
With the updates of Wordpress, it has been a long time, the php mail function has been becoming inoperative.
Try these free ones:

or

We use the latest version of WordPress on all of our sites (set to auto-update). Plus we run our own server infrastructure. We try to avoid plugins if not needed. As I indicated near the beginning of this thread I have never encountered this issue on WordPress sites on any of our servers prior to trying out Virtualmin boxes.

A small update: my first Virtualmin server with about thirty WordPress sites on it - had no sites that had forms. I threw a form into a site and tested it and it worked first time out. No adding of plugins or changes of any kind.

Now the fun of comparing configuration files to see what is different…

Is Mail for Domain enabled?