【问题标题】:Function is not not working inside PHP mail body函数在 PHP 邮件正文中不起作用
【发布时间】:2019-03-09 03:41:40
【问题描述】:

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

// 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.

仅供参考the_plugins() 功能有效。我可以在函数之后echo the_plugins(); exit;,它会返回一个插件列表,所以函数本身不是问题。

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

【问题讨论】:

  • 从函数返回字符串。并删除打印语句。
  • @ShoyebSheikh 你的意思是这样的:return $string = explode('/',$value); print $string[0] . '&lt;br /&gt;'; 如果我这样做,它会返回Array
  • 我发布了答案

标签: php wordpress function email


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-05
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    相关资源
    最近更新 更多