0

I developed under WordPress a page that receives a JSON containing an email address and automatically sends an email using wp_mail.

Here is the code related to wp_mail :

// Not loading WP templates...
define( 'WP_USE_THEMES', false );

// Load WordPress Core (make sure the path is correct)
$path = preg_replace('/wp-content.*$/','',__DIR__);
$path = preg_replace('/wp-content(?!.*wp-content).*/','',__DIR__);
include($path.'wp-load.php');


$to = $email ;
$subject = 'Arbre planté';
$body = '<html><body><h1>Hello World!</h1></body></html>';
$headers = array('Content-Type: text/html; charset=UTF-8','From: Kevin Brosseau <kevin@warenghem.com>');

wp_mail( $to, $subject, $body, $headers );

The issues are:

  • The subject is in the body
  • The "from" email addres "is in the subject
  • Emails do not always arrive (rarely)
  • HTML does not work
  • I have the following PHP warning: <b> Warning </b>: call_user_func_array () expects parameter 1 to be a valid callback, function 'wpb_sender_email' not found or invalid function name in <b> / home / clients / 401db14e9680969ee897423a6a744d86 /warenghem/wp-includes/class-wp-hook.php </b> on line <b> 287 </b> <br />

I looked for solutions in vain ... Could you help me?

Have a good day

Kevin
  • 13
  • 3
  • How is this code accessed? It appears to be a regular PHP page that is attempting to boot WordPress manually and not a real WordPress page. I would start by letting WordPress boot normally by either creating a true page, [registering a custom end point](https://stackoverflow.com/a/53127020/231316) or some other fashion. – Chris Haas Jun 09 '20 at 11:55
  • Yes it is a regular PHP page, the adress is : www.warenghem.com/wp-content/themes/susty-master/api/bot/callback.php. I thought it was a better option as it is just an API callback and email send. What do you mean by creating a true page? – Kevin Jun 09 '20 at 12:07
  • For the emails not arriving you can use a service like https://www.mail-tester.com/ to see if there is any spam filter or anything blocking the mails from going through. – Timberman Jun 09 '20 at 12:14
  • I tried to use PHPmailer and it s work better. – Kevin Jun 09 '20 at 14:30

0 Answers0