Our server is currently automatically setting the return path as {[email protected]}. When sending an email in PHP, I can override this by doing the following:
$return = '<[email protected]>';
$additional = "-f$return";
mail($to,$subject,$message,$headers, $additional);
My problem is that WordPress doesn't offer the functionality to add additional_parameters like the native PHP Mail function does. Is there a workaround to get this working? Here's the actual code that my WordPress plugin is using to send the email:
$headers = array(
'From: Eden Mobility <[email protected]>',
'Content-Type: text/html; charset=UTF-8',
'Return-Path: <[email protected]>'
);
wp_mail( "[email protected]", 'Your ' . $item . ' renewal is almost due', $template, $headers ); // LIVE
One thing I have noticed is that I'm now getting warnings when submitting mail:
PHP Warning: escapeshellcmd() has been disabled for security reasons in /home/user/domain.co.uk/wp-includes/class-phpmailer.php on line 1442
[02-Feb-2018 15:25:54 UTC]
Our server is currently automatically setting the return path as {[email protected]}. When sending an email in PHP, I can override this by doing the following:
$return = '<[email protected]>';
$additional = "-f$return";
mail($to,$subject,$message,$headers, $additional);
My problem is that WordPress doesn't offer the functionality to add additional_parameters like the native PHP Mail function does. Is there a workaround to get this working? Here's the actual code that my WordPress plugin is using to send the email:
$headers = array(
'From: Eden Mobility <[email protected]>',
'Content-Type: text/html; charset=UTF-8',
'Return-Path: <[email protected]>'
);
wp_mail( "[email protected]", 'Your ' . $item . ' renewal is almost due', $template, $headers ); // LIVE
One thing I have noticed is that I'm now getting warnings when submitting mail:
PHP Warning: escapeshellcmd() has been disabled for security reasons in /home/user/domain.co.uk/wp-includes/class-phpmailer.php on line 1442
[02-Feb-2018 15:25:54 UTC]
1 Answer
Reset to default 1Yes! There's a plugin that does this, and it's very simple. It uses the phpmailer_init
to adjust the $phpmailer
object. This is the code it uses:
if ( ! function_exists( 'wp_mail_returnpath_phpmailer_init' ) ) {
function wp_mail_returnpath_phpmailer_init( $phpmailer ) {
// Set the Sender (return-path) if it is not already set
if ( filter_var( $params->Sender, FILTER_VALIDATE_EMAIL ) !== true ) {
$phpmailer->Sender = $phpmailer->From;
}
}
}
add_action('phpmailer_init','wp_mail_returnpath_phpmailer_init');
https://plugins.trac.wordpress/browser/wp-mail-returnpath/trunk/index.php
escapeshellcmd
and re-tried, but it's the exact same outcome. I think I'll reach out to the server support team to see if they're aware of anything that could cause the issue. – Liam McArthur Commented Feb 2, 2018 at 16:58