Support » Developing with WordPress » Send e-mail when i save post type

  • Hello everybody !
    I want to add a feature to my custom post type. On my website, i have a custom post type to display the car of a company.

    I want, on the back office to add 3 buttons:
    – First button send a email to buyer “Your order is ok”
    – Second button send a email to buyer “Your car is ready”
    – Third button send a email to buyer “Thanks for your purchase”

    So, my question is:
    I want to, when the adminsitrator clic on the button on the page of the custom post type (on the back office) he send the email to the buyer. But i try with this code and its dont work..

    function sendMail() {
        if($_POST['save']) {
    		$to = '';
    		$subject = 'The subject';
    		$body = 'The email body content';
    		$headers = array('Content-Type: text/html; charset=UTF-8');
    		wp_mail( $to, $subject, $body, $headers );

    And my second question is, i want to lock the 2 & 3 button when the 1 is not click. When the adminsitrator click on the button 1, the 2 was unlock and the 1 & 3 was lock (prevent dont send the same mail twice)

    Thanks for your help

    • This topic was modified 9 months, 1 week ago by  Haandler.
    • This topic was modified 9 months, 1 week ago by  Andrew Nevins.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    What causes sendMail() to execute? Where are you POSTing data to? Either the function is not executing or wp_mail() is out of scope because of where you POSTed the data to. If you wish to use the wp_mail() function, you are limited on where you can POST to. You can POST to a WP page that uses a custom template whose code handles the POSTed data. You can use Ajax techniques to save the data and send emails. Finally, you can POST to /wp-admin/admin-post.php with an “action” parameter whose value is used to create an action tag that is fired. You add a callback to that action in order to process the POSTed data. If you do anything else, you cannot use wp_mail().

    You can manage the lock status by keeping track of where the order is in the process and setting the appropriate form input field attribute disabled accordingly. The status could be saved in a custom field of the post type’s WP Post object. For example, if status is “1”, buttons 2 and 3 have disabled attributes. When status is “2”, buttons 1 and 3 are disabled. And so on.

    When one button click is processed, the status can automatically be updated to the next logical status. An admin could override the automatic status by altering the value on the custom post type’s normal edit screen.

Viewing 1 replies (of 1 total)
  • The topic ‘Send e-mail when i save post type’ is closed to new replies.