Title: function to send predefined mails
Last modified: October 15, 2025

---

# function to send predefined mails

 *  [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [7 months, 2 weeks ago](https://wordpress.org/support/topic/function-to-send-predefined-mails/)
 * Is this code correct?
 *     ```wp-block-code
                       <?php$subject= $post->ID;$message= esc_html__('Don\'\t forget to insert the number of people','sacconicase');echo '<form><a href=\"mailto: subject=$subject&body=$message\"><input type="button" class="listino" value=" '. esc_html__('Availability','sacconicase').' " ></a></form>';                                ?>
       ```
   
 * When I click on a specific button an email container should open with for subject
   the post ID of that specific page, and in the body a gettexted message
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffunction-to-send-predefined-mails%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [7 months, 2 weeks ago](https://wordpress.org/support/topic/function-to-send-predefined-mails/#post-18682167)
 * Even if it is syntactically correct, no, I would not use it that way for several
   reasons:
 * a) The form around it is completely unnecessary.
   b) The space after mailto: can
   be a problem.c) Labeling the link as a button is not really useful in terms of
   accessibility, for example.
 * **It would be better to use:**
 *     ```wp-block-code
       <?php$subject= $post->ID;$message= esc_html__('Don\'\t forget to insert the number of people','sacconicase');echo '<a href=\"mailto:subject=$subject&body=$message\">'. esc_html__('Availability','sacconicase').'</a>';                ?>
       ```
   
 * **But that doesn’t make it right.** Because with this approach, you are preventing
   many of your visitors from contacting you at all. Not everyone has an email program
   on their computer or cell phone that would start when they click on this link.
   Those visitors would only see a message from their browser saying “unknown protocol”
   or something similar – and you would have lost them as potential customers.
 * Instead, I would recommend using contact forms. There are many plugins to choose
   from: [https://wordpress.org/plugins/tags/contact-form/](https://wordpress.org/plugins/tags/contact-form/)
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [7 months, 2 weeks ago](https://wordpress.org/support/topic/function-to-send-predefined-mails/#post-18682193)
 * I already have a contact page, this is a temporary solution until I implement
   the search by date/calendars tool, maybe in one year. I never use contact forms
   because in my experience people make a lot of errors in typing and I simply cant
   reply…and nowadays who hasnt at least a gmail in his telephone? Mail is a default
   tool
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [7 months, 2 weeks ago](https://wordpress.org/support/topic/function-to-send-predefined-mails/#post-18682249)
 * Anyway the code is not working even after removing the space after mailto:

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

The topic ‘function to send predefined mails’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [sacconi](https://wordpress.org/support/users/sacconi/)
 * Last activity: [7 months, 2 weeks ago](https://wordpress.org/support/topic/function-to-send-predefined-mails/#post-18682249)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
