php - 函数在 PHP 邮件正文中不起作用
问题描述
我用它来发送一个基本的电子邮件:
// 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;
在函数之后立即返回插件列表,因此函数本身不是问题。
关于如何解决这个问题的任何建议?
解决方案
尝试这个,
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;
}
推荐阅读
- javascript - 如果Xpath返回元素列表(selenium-python),如何找到第一个元素
- r - 将 sf 文件与不同的几何类型组合,然后在 r 中找出哪些文件彼此在一定距离内
- flutter - 通过监听 pageController 重建部分页面
- javascript - 修改我以前有效的本机应用程序内容后,海拔突然无法正常工作
- java - 带有 spark 库的 AWS Lambda 给出 OutOfMemoryError
- angularjs - 如何放置正确的值来选择由 angularjs 生成的选项值?
- c - 测试一个目录是否设置了 MS_NOEXEC 标志?
- sql - 在不更改游标位置的情况下检查 SQL SYS_REFCURSOR
- f# - 如何在 F# 中派生记录类型?
- c# - Span 类型是否意味着堆栈不再是“实现细节”?