I have been trying for a while now to use wp_mail to send an email from within my plugin. The code I'm using is as follows.

function add_page_content_Send_Feed(){
    echo "<h2>Send your feed via email</h2>";

    echo "<form id='post' action='' method='POST'>";
    echo "<input type='submit' name='send_feed' value='Send my feed' id='submit';'/>";
    echo "</form>";

    // Example using the array form of $headers
    // assumes $to, $subject, $message have already been defined earlier...

    $headers[] = 'From: UltraIT <demo@ultrait.org>';
    $headers[] = 'Cc: John Q Codex <jqc@wordpress.org>';
    $headers[] = 'Cc: iluvwp@wordpress.org'; // note you can just use a simple email address

    $to = 'jesseorange360@gmail.com';
    $subject = 'TESTING';
    $message = 'hello'; 

    if(isset($_POST['send_feed'])) {
        wp_mail( $to, $subject, $message, $headers);


This however is not working... Can anyone tell me what I'm doing wrong?

  • 1
    This id='submit';' should be id='submit'. How are you calling / hooking that function?
    – shanebp
    Jan 9, 2015 at 15:58
  • I thought if I called the function on submit it would then run the function and send my email. Is it not that straightforward?It seemed too good to be true...
    – Blorange2
    Jan 9, 2015 at 16:06
  • The function is added on the end of an add_submenu_page
    – Blorange2
    Jan 9, 2015 at 16:07

1 Answer 1


Your code works well when put in a page template, so what is currently wrong in your case most probably is the usage of the wrong hook in the wrong place.

Just an example of how you can hook this:

add_action('ahook', 'add_page_content_Send_Feed'); //add this after your function definition

Then you can use this in any page or other template of the theme (or other plugin):


'ahook' can be a hook you made up, but you can replace it by some specific one that you want to use depending on your specific case.

Another thing you can do is define a shortcode and apply this button just anywhere in your content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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