Title: Submit button
Last modified: August 30, 2016

---

# Submit button

 *  [demitsin](https://wordpress.org/support/users/demitsin/)
 * (@demitsin)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/)
 * Hi, I have created o form by my own and i cannot find how to to send it to my
   email via submit button. This is the beggining of the form: <form action=”emailadress.
   php” method=”post” name=”flightplan”>
 * I downloaded a plugin which allows php code. This is the plugin:
    [https://wordpress.org/plugins/custom-css-js-php/screenshots/](https://wordpress.org/plugins/custom-css-js-php/screenshots/)
 * Any help?
 * Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  anonymized-13749270
 * (@anonymized-13749270)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820577)
 * Try this basic form using wp_mail(’email address’, ‘subject’, ‘message’); function
   to send out the email
 *     ```
       <?php
   
       //require_once(ABSPATH.'wp-blog-header.php');
       $my_email = 'email@addr.es';
       $subject = 'Testing a form..';
       if( isset( $_POST['send'] ) ) {
       	$text = isset( $_POST['text'] ) ? sanitize_text_field($_POST['text']) : '';
       	if( $text !== '' ) {
       		wp_mail($my_email, $subject, $text);
       		echo '<p>Email sent!</p>';
       	}
       }
       ?>
       <form action="" method="post">
       	<textarea name="text" placeholder="Enter your message here" rows="4" cols="50"></textarea>
       	<br />
       	<input type="submit" value="Send" name="send" />
       </form>
       ```
   
 *  Thread Starter [demitsin](https://wordpress.org/support/users/demitsin/)
 * (@demitsin)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820644)
 * I tried this code and when i choose send, the message “email sent” is appeared
   but i don’t receive any email.
 * Something which works is this:
    <form action=”MAILTO:my_email@gmail.com” method
   =”post” name=”” enctype=”text/plain”>
 * Thanks for your help!
 *  anonymized-13749270
 * (@anonymized-13749270)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820647)
 * Did you add your email address in this line `$my_email = 'email@addr.es';` ? 
   Are you trying to run the email on localhost?
 * You’re welcome.
 *  Thread Starter [demitsin](https://wordpress.org/support/users/demitsin/)
 * (@demitsin)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820670)
 * Well, i had writen something wrong. It works!
 * One last question:
    My form comsist of a lot of fields. So, should i write the
   code
 *     ```
       $text = isset( $_POST['text'] ) ? sanitize_text_field($_POST['text']) : '';
       	if( $text !== '' ) {
       		wp_mail($my_email, $subject, $text);
       		echo '<p>Email sent!</p>';
       	}
       ```
   
 * for each field seperately?
 *  anonymized-13749270
 * (@anonymized-13749270)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820671)
 * Just add more additional fields in the form (HTML) ie:
 *     ```
       <textarea name="text" placeholder="Enter your message here" rows="4" cols="50"></textarea>
       <input type="email" name="your_email" placeholder="your email" />
       <input type="url" name="your_website" placeholder="your website" />
       ```
   
 * And to get their values use `$_POST` asosiated with their name attributes:
 *     ```
       $_POST["your_email"]
       $_POST["your_website"]
       ```
   
 * And since you’re just emailing the output to yourself (not inserting to a database)
   you don’t need to worry about sanitizing or stripping html so as to avoid SQL
   injection, just, add the values to `$text` variable which will be sent at the
   end:
 *     ```
       $text = isset( $_POST['text'] ) ? sanitize_text_field($_POST['text']) : '';
   
       $text .= isset( $_POST['my_email'] ) ? "\n" . $_POST['my_email'] : '';
       $text .= isset( $_POST['my_email'] ) ? "\n" . $_POST['my_email'] : '';
   
       if( $text !== '' ) {
       	wp_mail($my_email, $subject, $text);
       	echo '<p>Email sent!</p>';
       }
       ```
   
 * Have fun with your code 😉
 *  Thread Starter [demitsin](https://wordpress.org/support/users/demitsin/)
 * (@demitsin)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820680)
 * OK! Thanks again for your help!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Submit button’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [demitsin](https://wordpress.org/support/users/demitsin/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/submit-button-27/#post-6820680)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
