Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts

    Tweaking php action page so all fields appear in e-mail

    I found a php and html comment form online. I'm new to php, and so far I have been able to make the form work. This is interesting. I have added two fields to the php page and to the form.

    Right now, when the form is sent, all that appears in the "Web master" e-mail is the comment field information. What do I need to change or add so that all the fields and their content show up in the e-mail that is sent to me?

    I would like the comment to appear, the sender's name, their telephone number, and their e-mail address.

    This is the php code that I'm using. I added the name and telephone number fields.

    PHP Code:
    <?php
    /*
    This is the e-mail address you want to send to.
    */
    $webmaster_email "editor@theeagleextra.com";

    /*
    These are the URLs of supporting pages.
    */
    $feedback_page "feedback_form.html";
    $error_page "error_message.html";
    $thankyou_page "thank_you.html";

    /*
    This loads the form field data into variables;
    add additional fields here.
    */
    $comments $_REQUEST['comments'] ;
    $name $_REQUEST['name'] ;
    $telephone $_REQUEST['telephone'] ;
    $email_address $_REQUEST['email_address'] ;
    /*
    This checks for e-mail injection and carriage return
    used by spammers to inject CC list.
    */
    function isInjected($str) {
        
    $injections = array('(\n+)',
        
    '(\r+)',
        
    '(\t+)',
        
    '(%0A+)',
        
    '(%0D+)',
        
    '(%08+)',
        
    '(%09+)'
        
    );
        
    $inject join('|'$injections);
        
    $inject "/$inject/i";
        if(
    preg_match($inject,$str)) {
            return 
    true;
        }
        else {
            return 
    false;
        }
    }

    // If user tries to access php script directly, redirect to the comment form.
    if (!isset($_REQUEST['email_address'])) {
    header"Location: $feedback_page" );
    }

    // If any fields in form are empty, redirect to the error page.
    elseif (empty($comments) || empty($name) || empty($telephone) || empty($email_address)) {
    header"Location: $error_page" );
    }

    // If email injection is detected, go to error page.
    elseif ( isInjected($email_address) ) {
    header"Location: $error_page" );
    }

    // Send email then redirect to the thank you page if all things met.
    else {
    mail"$webmaster_email""Feedback Form Results",
      
    $comments"From: $email_address" );
    header"Location: $thankyou_page" );
    }
    ?>
    Any help would be appreciated. Thanks.

    --Kevin

    .
    My keyboard is an IBM from 1993 and I like it that way. | Who is Dan Well? Everyone always says I know Dan Well.Building a web page is like building a birdhouse. Put it up there and watch 'em come. | Maintaining the aspect ratio of an image is more important than having a cold orange pop.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Its a simple matter of making what you want to show:
    PHP Code:
    $body 
    'Name: ' $name .
    'Email: ' $email_address 
    'Telephone Number: ' $telephone 
    PHP_EOL 
    'Comments: ' $comments
    Then sending the mail() with $body instead of $comments. $body here has to be done after those variables are created.

  • #3
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts
    Fou-Lu,

    Thank you for the reply. I'm not altogether clear as to where to insert the "body", is this correct?

    PHP Code:
    // If email injection is detected, go to error page.
    elseif ( isInjected($email_address) ) {
    header"Location: $error_page" );
    }

    $body 
    'Name: ' $name .
    'Email: ' $email_address 
    'Telephone Number: ' $telephone 
    PHP_EOL 
    'Comments: ' $comments;

    // Send email then redirect to the thank you page if all things met.
    else {
    mail"$webmaster_email""Feedback Form Results",
      
    $body"From: $email_address" );
    header"Location: $thankyou_page" );
    }
    ?> 
    I did get an error on the line that begins with "else." This is all new to me, so much of this is confusing. I do catch on quick, though, it just takes a bit to understand what I'm doing.

    --Kevin

    .
    My keyboard is an IBM from 1993 and I like it that way. | Who is Dan Well? Everyone always says I know Dan Well.Building a web page is like building a birdhouse. Put it up there and watch 'em come. | Maintaining the aspect ratio of an image is more important than having a cold orange pop.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You cannot break an if/elseif/else with expressions between. The $body can go either immediately after the creation of the variables in use, or within the else.

  • Users who have thanked Fou-Lu for this post:

    Kevin_M_Schafer (01-23-2012)

  • #5
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts
    I repositioned the body above the "If". That worked. Thank you for your help, Fou-Lu. I appreciate it.

    --Kevin

    .
    My keyboard is an IBM from 1993 and I like it that way. | Who is Dan Well? Everyone always says I know Dan Well.Building a web page is like building a birdhouse. Put it up there and watch 'em come. | Maintaining the aspect ratio of an image is more important than having a cold orange pop.


  •  

    Posting Permissions

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