函数在PHP邮件正文中不起作用

时间:2019-03-09 03:41:40

标签: php wordpress function email

我正在使用它发送基本电子邮件:

// Email details
$name = 'Davo';
$recipient = 'info@davo.com';
$from = 'sender@example.com'
$subject = 'Testing';

// All plugins
function the_plugins() {
    $the_plugs = get_option('active_plugins'); 
    foreach($the_plugs as $key => $value) { 
        $string = explode('/',$value); print $string[0] . '<br />';
    }
}

// Message
$body = '<p>Hello' . $name . ',</p>';
$body .= '<p>Your website has these plugins:</p>';
$body .= the_plugins();
$body .= '<p>Have a nice day.</p>';

$headers[]  = 'Content-type:text/html;charset=UTF-8';
$headers[]  = 'From' . $name. ' <' . $from . '>';
$headers[]  = 'Reply-To: ' . $from;
$headers[]  = 'MIME-Version: 1.0';
wp_mail($recipient, $subject, $body, $headers);

唯一不起作用的是the_plugins()函数不会在收到的电子邮件中显示任何内容。相反,它只是在我希望看到插件列表的行中为空,如下所示:

Hello Davo,
Your website has these plugins:

Have a nice day.

FYI the_plugins()函数起作用。我可以在功能之后echo the_plugins(); exit;进行操作,它返回插件列表,因此功能本身不是问题。

关于如何解决此问题的任何建议?

1 个答案:

答案 0 :(得分:1)

尝试一下

function the_plugins() {
    $the_plugs = get_option('active_plugins'); 
    $plugins = '';
    foreach($the_plugs as $key => $value) { 
        $string = explode('/',$value); 
        $plugins .= $string[0] . '<br />';
    }
   return $plugins;
}