Call to undefined function wp_mail

wp_mail error
what is wp_mail
wp_mail not working in functions php
wp_mail headers not working
wordpress mail function not working
wp_mail reply-to
wp_send mail
wp_sendmail

Hi im using this function by Wordpress in a Cron webpage and is throwing this error on my email

Fatal error: Call to undefined function wp_mail() in /home/meusite/public_html/wp-content/themes/escotec/page-cron.php on line 33

Here the code

foreach($inscricoes as $key => $item){



    $emailSent = false;



    $emailTo = "$item->getEmail()";

//echo "..1";

    $subject = '[Escotec]: Dados para pagamento de inscrição ';
    $body = "Parabéns $inscricao->nome, sua inscrição no curso ".$item->getTurmas()[0]->getCurso()->getNome()." foi efetuada. <p>Para concluir o pagamento da inscrição clique no link abaixo ou cole-o diretamente na barra de endereços de seu Navegador: </p><br>";
    $body .= "<a href=\"http://escotecnordeste.com.br/pagamento/?email=".$item->getEmail()."&pedido=".$item->getPagamentoId()."\" target=\"_blank\">http://escotecnordeste.com.br/pagamento/?email=".$item->getEmail()."&pedido=".$item->getPagamentoId()."</a>";
    $headers = 'From: Escotec Nordeste <escotecnordeste@gmail.com>' . "\r\n" . 'Reply-To: ' . 'escotecnordeste@gmail.com';





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


    $emailSent = true;
// http://escotecnordeste.com.br/pagamento/?email=leandrocezar.dev@gmail.com&pedido=11

// Codificar envio do e-mail
    if ($emailSent) {
    // Atualizar registro do pedido para email_enviado = 'S'

        InscricaoDAO::RegistraEnvioEmail($item->getPagamentoId());
    }
}

Ty for help

please add below code in you file. where you have called wp_mail() function.

Add this code top of your file.

require_once("../../../wp-load.php");

or change your function wp_mail() to mail()

Call to undefined function wp_mail, please add below code in you file. where you have called wp_mail() function. Add this code top of your file. require_once("../../../wp-load.php");. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

You are calling function wp_mail() which can be included by wp-load.php .

require_once("wp-load.php");

wp_mail() function not working? Here's how to fix it, "wp_mail() function not working" is a common problem raised by PHP Fatal error: Uncaught Error: Call to undefined function wp_mail()  Emails stuck in mail queue. This is one of the common causes. wp_mail() function generates mails, but they are stuck in the mail queue. It can be due to various reasons. High load on the server.

The function wp_mail() has not been defined yet. Is this all the code on this page? wp_mail() is in this file. wp-includes/pluggable.php. You have to include it before the function is called.

Call to undefined function wp_mail, Fatal error: Call to undefined function wp_mail() in /home/meusite/public_html/wp​-content/themes/escotec/page-cron.php on line 33. Here the  EDITORIAL NOTE: Opinions expressed here are author’s alone, not those of any hosting company, plugin provider, theme company, Syed Balkhi or WordPress Foundation, and have not been reviewed, approved or otherwise endorsed by any of these entities.

You need to require wp-load.php, in that way the function can be used with no problems, that file loads every function of wordpress

If your path is /home/meusite/public_html/wp-content/themes/escotec/page-cron.php then use this path to require wp-load:

require_once( dirname(__FILE__) . '/wp-load.php' );"





foreach($inscricoes as $key => $item){



$emailSent = false;



$emailTo = "$item->getEmail()";

//echo "..1";

$subject = '[Escotec]: Dados para pagamento de inscrição ';
$body = "Parabéns $inscricao->nome, sua inscrição no curso ".$item->getTurmas()[0]->getCurso()->getNome()." foi efetuada. <p>Para concluir o pagamento da inscrição clique no link abaixo ou cole-o diretamente na barra de endereços de seu Navegador: </p><br>";
$body .= "<a href=\"http://escotecnordeste.com.br/pagamento/?email=".$item->getEmail()."&pedido=".$item->getPagamentoId()."\" target=\"_blank\">http://escotecnordeste.com.br/pagamento/?email=".$item->getEmail()."&pedido=".$item->getPagamentoId()."</a>";
$headers = 'From: Escotec Nordeste <escotecnordeste@gmail.com>' . "\r\n" . 'Reply-To: ' . 'escotecnordeste@gmail.com';





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


$emailSent = true;
// http://escotecnordeste.com.br/pagamento/?email=leandrocezar.dev@gmail.com&pedido=11

// Codificar envio do e-mail
if ($emailSent) {
// Atualizar registro do pedido para email_enviado = 'S'

    InscricaoDAO::RegistraEnvioEmail($item->getPagamentoId());
}
}

wp_mail is undefined, You may call the function too early. You have to wait until the action '​plugins_loaded' fires. wp_mail() is defined in wp-includes/pluggable.php . The “Fatal error: Call to undefined method” or “Fatal error: Call to undefined function” messages that reference one of your theme’s files or one of your plugins, are coming from that theme or plugin.

This worked for me:

add_action( 'wp_loaded', 'cron_time' );

It works everywhere and almost always and especially for ajax.

Do not include wordpress core files. It is bad practice. Like this:

require_once( dirname(__FILE__) . '/wp-load.php' );

Urgent – Fatal error: Call to undefined function WPMailSMTP\Admin , [This thread is closed.] WordPress version 3.6.1 When click on the option wp smtp mail in the backend I got this error. Fatal error: Call to undefined…

Sending mail with PHP mail, Postman: wp_mail has been declared by another plugin or theme, so you won't be able to use 'Fatal error: Call to undefined function is_user_logged_in()'.

Error when invoking wp_mail() from within a plugin - CMS , wp_mail(). function. My plugin is intended to be used by a visitor to the site to send an invitation and prints in the error log that it is undefined.

8887 - WordPress.org Forums » All Topics, Как избежать ошибки Call to undefined function wp_mail() в Ajax. Что я только не пробовал чтоб подключить мою функцию в хук "plugins_loaded" ведь для 

Comments
  • please try wordpress.stackexchange.com/questions/74632/…
  • Its weird I did not nothing and the error dissapear, but sometimes back to giving the email with error