最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Pass return-path additional parameter in wp_mail

programmeradmin0浏览0评论

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]

Share Improve this question edited Feb 2, 2018 at 15:29 Liam McArthur asked Feb 2, 2018 at 14:31 Liam McArthurLiam McArthur 2311 silver badge8 bronze badges 2
  • the warning is something your host can clarify on, looks like they've disabled a PHP function – Tom J Nowell Commented Feb 2, 2018 at 16:55
  • I've logged into my server and enabled 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
Add a comment  | 

1 Answer 1

Reset to default 1

Yes! 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

发布评论

评论列表(0)

  1. 暂无评论