Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
        generatePDF($html);
        unset($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 = 'myemail@domain.com';
    $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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
thanks it worked –  ntechi Dec 2 '12 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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