Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function wp_mail

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 <[email protected]>' . "\r\n" . 'Reply-To: ' . '[email protected]';





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


    $emailSent = true;
// http://escotecnordeste.com.br/pagamento/[email protected]&pedido=11

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

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

Ty for help

like image 480
lucas_cezar Avatar asked Jul 08 '15 13:07

lucas_cezar


3 Answers

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()

like image 58
Anand Avatar answered Sep 20 '22 06:09

Anand


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

require_once("wp-load.php");
like image 25
Sourabh Bhutani Avatar answered Sep 23 '22 06:09

Sourabh Bhutani


Solution provided by Tonny works for me. My code:

function your_function_name() {
        $to =' [email protected]';
        $subject = 'The subject';
        $body = 'The email body content';
        $headers = array('Content-Type: text/html; charset=UTF-8');
        wp_mail( $to, $subject, $body, $headers );
}
add_action( 'wp_loaded', 'your_function_name' );
like image 24
Artus2000 Avatar answered Sep 22 '22 06:09

Artus2000