sending mail after payment paypal contact form 7

I have a form with contact form 7 in a WordPress site.
When you click on “submit” you are redirected on Paypal and pleased to pay :). Everything works well, but the I want something more.
I want to send the mail, ONLY when visitors have pay on Paypal.
I’ve searched on google, but I don’t have found the way to do this.

Any ideas ?

Read More

Thanks !

Nathan

Related posts

2 comments

  1. You can use PayPal IPN to get this done. There is a free plugin available to get PayPal IPN setup in WordPress very easily, but then you’ll need to make a basic hook from your functions.php file (or your own plugin) to trigger the email based on when you want it sent.

    You can trigger any action you want based on different PayPal transaction types or payment status.

    Here is a very basic example of sending an email from an extension to the IPN plugin. This is a full plugin file with nothing but a hook to the plugin. In this case I’m using the paypal_ipn_for_wordpress_txn_type_cart hook.

    <?php
    /**
     * @package PayPal IPN for WordPress - Hook Template
     * @version 1.0.0
     */
    /*
    Plugin Name: PayPal IPN for WordPress - Hook Template
    Plugin URI: http://www.angelleye.com/
    Description: Hook tester for PayPal IPN for WordPress plugin.
    Author: angelleye
    Version: 1.0.0
    */
    
    
    add_action('paypal_ipn_for_wordpress_txn_type_cart', 'paypal_ipn_for_wordpress_txn_type_cart', 10, 1);
    function paypal_ipn_for_wordpress_txn_type_cart($posted) {
    
        // Parse data from IPN $posted array
    
        $payment_status = isset($posted['payment_status']) ? $posted['payment_status'] : '';
        $mc_gross = isset($posted['mc_gross']) ? $posted['mc_gross'] : '';
        $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
        $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
        $cart_items = isset($posted['cart_items']) ? $posted['cart_items'] : '';
    
        /**
         * At this point you can use the data to generate email notifications,
         * update your local database, hit 3rd party web services, or anything
         * else you might want to automate based on this type of IPN.
         */
        $to = 'email@domain.com';
        $subject = 'Email from PayPal IPN';
        $message = 'Order Total: ' . $mc_gross . "n";
        $message .= 'Payment Status: ' . $payment_status . "n";
        $message .= 'Name: ' . $first_name . ' ' . $last_name . "n";
        $message .= 'Cart Items: ' . print_r($cart_items, true);
        wp_mail( $to, $subject, $message );
    }
    

    So with both the IPN plugin and this plugin installed on your site, any time a cart transaction is made on your PayPal account an email would be sent accordingly. This is a sample of the email I received when running a test transaction on PayPal with this plugin activated on the site.

    Order Total: 90.27
    Payment Status: Completed
    Name: Tester Testerson
    Cart Items: Array
    (
        [0] => Array
            (
                [item_number] =>
                [item_name] => Woo Album #2
                [quantity] => 1
                [mc_gross] => 75.27
                [mc_handling] => 0.00
                [mc_shipping] => 0.00
                [custom] =>
                [option_name1] =>
                [option_selection1] =>
                [option_name2] =>
                [option_selection2] =>
                [btn_id] =>
                [tax] => 0.00
            )
    
    )
    

    Of course, you could spend the time to make the email more pretty and send it to any email address(es) you need to.

    So again, you can use lots of different hooks to trigger your own plugin functions like this based on different IPN types or payment status.

    The sample here only includes a few data parameters that IPN provides, but the IPN record in WordPress will give you a template you can easily copy/paste into your own plugin file that includes every IPN parameter available to that type of IPN.

Comments are closed.