SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    0 Post(s)
    0 Thread(s)

    Add Custom Field and email message

    I have a form in php in "single.php" from my site (wordpress). In it, the person adds your email address and a specific message is sent to it.
    I would like to modify this form for a custom field is sent along the message she receives.
    What I need to modify my code?

    <? php
    if (isset ($ _POST ['action']) && $ _POST ['action'] == 'email-att ") {
    *** if (is_email ($ _POST ['email'])) {
    ******** $ to = $ _POST ['email'];
    ******** $ subject = "email subject line";
    ******** $ message = "email message body";
    ******** $ attachments = array ('');
    ******** wp_mail ($ to, $ subject, $ message,'', $ attachments);
    ******** echo 'Email sent! Check your email ';
    **** else {}
    ******** echo 'Please enter a valid email address';
    **** }

    <form name="email-att" id="email-att" method="POST" action="">
    Enter your emial: <br />
    <input type="text" name="email" id="email"/> <br />
    <input type="hidden" name="action" value="email-att"/> <br />
    <input type="submit" name="submit" value="Submit" id="submit"/>
    </ form>

    these two codes are together in single.php

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    PHP Code:
    <? php
    if (isset ($ _POST ['action']) && $ _POST ['action'] == 'email_att') {

      if (
    is_email ($_POST ['email'])) {
    $to = $ _POST ['email'];
    $subject "email subject line";
    $message "email message body";
    $attachments '';
    wp_mail ($to$subject$message,''$attachments);
    'Email sent! Check your email ';
    'Please enter a valid email address';

    <form name="email_att" id="email_att" method="POST" action="">
    Enter your email: <br />
    <input type="text" name="email" id="email"/> <br />
    <input type="hidden" name="action" value="email_att"/> <br />
    <input type="submit" name="submit" value="Submit" id="submit"/>
    Give that a try (untested).

    PHP vars (and hence the form elements submitted to it) cannot contain hyphens - variables

    The code you posted had spaces between the $ and the variable name, not allowed.

    $attachments was an array (with one item) yet you tried to submit the array, read the man page on mail for more information.

    I would test this without the attachments first, then add them when you are sure the rest of it is working as it should be.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts