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>' . "rn" . '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.
or change your function
wp_mail()
tomail()
You are calling function wp_mail() which can be included by
wp-load.php
.Solution provided by Tonny works for me. My code:
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.
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:
This worked for me:
It works everywhere and almost always and especially for ajax.
Do not include wordpress core files. It is bad practice. Like this: