I am using a plugin wordpress-simple-paypal-shopping-cart for my cart requirement. I am trying to send an email through this plugin when some payment is made by using IPN.

My code :

$invoiceProducts = $_SESSION['simpleCart'];
    if(isset($invoiceProducts) && !empty($invoiceProducts)){
        $html = renderHTML($invoiceProducts);

function renderHTML($param){
    $IPN = $_POST;

    $name = $IPN['first_name'];
    $donationAmount = $IPN['payment_gross'];
    $contributorsEmail = $IPN['payer_email'];
    $contributorsPhone = $IPN['payer_email'];
    $contributorsAddr = $IPN['address_name'] . ', ' . $IPN['address_city'] . ', ' . $IPN['address_country'];

    //We will need to shoot email to laura of successfull payment.
    $to = '[email protected]';
    $subject = 'Donation made on your website';
    $message = '';
    $message .= '<html><body>';
    $message .= '<p>You have received a contribution from<strong>'.$name.'</strong> of <strong>'.$donationAmount.'</strong></p>';
    $message .= '<p>Contributor Information:</p>';
    $message .= '<ul>';
    $message .= '<li>Name:'.$name.'</li>';
    $message .= '<li>Amount:'.$donationAmount.'</li>';
    $message .= '<li>Email:'.$contributorsEmail.'</li>';
    $message .= '<li>Address:'.$contributorsAddr.'</li>';
    $message .= '</ul>';
    $message .= '</body></html>';

    wp_mail( $to, $subject, $message, $headers, $attachments );

But when this function is called I am getting this error : Fatal error: Call to undefined function wp_mail()

I know why I am getting this error, its just that my plugin is getting loaded first rather then wp_mail().

In my case how can I call wp_mail() first then my plugin?

1 Answer 1


wp_mail() is defined in wp-includes/pluggable.php. This file is loaded after the plugins are loaded, but before the hook plugins_loaded has been fired.
So the answer is: wait.

add_action( 'plugins_loaded', 'renderHTML' );

On a side note: prefix your function names and your global variables.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.