How can I use get_bloginfo('admin_email') in a custom PHP file?
-
11-04-2021 - |
Question
How can I use get_bloginfo('admin_email') in a custom PHP file located in the parent theme root directory?
I've built a custom form and a PHP mail script separately, but now I'd like to send the form data to the WP Admin email address with Bcc.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <example@gmail.com>' . "\r\n";
$headers .= 'Bcc: <'. get_bloginfo('admin_email');'>'. "\r\n";
mail("example2@gmail.com","Form Application",$admin_email_body,$headers);
Do I need to include Wordpress functions in the PHP file?
Thanks
Solution
You can include the wp-load.php
in your PHP file, but, I do not recommend this method. It's better you use the wp_enqueue_script()
.
See this article to get more information.
<?php
include "../../../wp-load.php";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <example@gmail.com>' . "\r\n";
$headers .= 'Bcc: <'. get_bloginfo('admin_email') . '>'. "\r\n";
mail("example2@gmail.com","Form Application",$admin_email_body,$headers);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange