www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP returning multiple fields; email format

  1. #1
    Join Date
    Aug 2009
    Posts
    4

    PHP returning multiple fields; email format

    Hello there, newb to the forums here
    I wouldnt consider myself a newbie in general but i still have a whole lot to learn. Im familiar with PHP scripting but i definitely wouldnt call myself an expert quite yet.

    I have a website that i've hosted some forms/contracts on that use php to return the data to me in email form. I've tried to use the same PHP script that I use for my contact us page as a template for the php for all my forms/agreements-just editing them a bit.

    The problem that i've run into is when a user clicks submit, I want it to obviously return to me all of the input data the user has typed in all of the text fields, as well as a couple radio button values.

    My problem is that when i recieve the email, it will only send me one field value at a time...for example I only recieve the user's name in my email when I should be collecting their name, address, credit card, etc......This was never a problem for my contact page because the only input field is the body of the message anyway.

    also, when the data is returned to me I need a better way of organizing it; right now if it sends me back someones name for example, it will simply say in the first and only line of my email message: John Smith.
    I would like it to say Name: John Smith, in other words Iwould like to receive the data in the closest form possible to the way i distributed it. if I ask for an email on my form i want it to come back as Email: email@email.com
    here's the code:

    PHP Code:
    <?php

    $name 
    trim($_POST['name']);
    $location trim($_POST['location']);
    $city trim($_POST['city']);
    $zip trim($_POST['zip']);
    $home trim($_POST['home']);
    $cell trim($_POST['cell']);
    $office trim($_POST['office']);
    $primaryfax trim($_POST['primaryfax']);
    $local trim($_POST['local']);
    $localfax trim($_POST['localfax']);
    $from trim($_POST['from']);
    $problem trim($_POST['problem']);
    $previousproblem trim($_POST['previousproblem']);
    $company trim($_POST['company']);
    $service trim($_POST['service']);

    function 
    checkEmail($from)
    {
       if(
    eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$from))
       {
          return 
    FALSE;
       }

       list(
    $Username$Domain) = split("@",$from);
       
       if(
    getmxrr($Domain$MXHost))
       {
          return 
    TRUE;
       }
       else
       {
          if(
    fsockopen($Domain25$errno$errstr30))
          {
             return 
    TRUE;
          }
          else
          {
             return 
    FALSE;
          }
       }
    }

    if( isset( 
    $_POST['submit'] ) || !empty( $_POST['submit'] ) )
    {
        
    $errors '';
       
        if(
    checkEmail($from) == FALSE)
        {
       
            if( empty(
    $from) )
            {
                
    $errors .= "<br/><strong>Please enter a valid Email address</strong><br/><br/>";
            } else {
                
    $errors .= "<strong>Your E-mail address entered is not valid, please go back and try again.<br/><br/></strong>";
            }
        }
       
        if ( empty(
    $name) ) { $errors .= "<strong>Please enter your full name.<br/><br/></strong>"; }
       
        if ( empty(
    $location) ) { $errors .= "<strong>Please enter a valid service call location.<br/><br/></strong>"; }

        echo 
    $errors;
           
        if ( empty(
    $errors) )
        {
            
    $sendTo "me@ my site .com";
            
    $subject SCAF;
            
    $headers "From: " $from;
            
    $message $name;$location;
            
    mail($sendTo$subject$message$headers);
            
    header("location: http://www. mysite. com/thanks.html");       
        }
    }

    ?>
    also, the "$service" value represents 4 different radio buttons, and I want the data returned to be whichever value the user chooses, how would I go about doing this?


    I am posting these and more questions on many web scripting forums hoping to get some good advice from knowledgeable people as I am kind of in a hurry to finish this up so my customers can fill out this years forms without snal mail or fax........I greatly appreciate all help,advice, and information you can provide for me. thanks!

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    PHP Code:
            $message $name;$location
    ; is PHPs way of marking the end of a line. Try something like:
    PHP Code:
    //....
    $message = <<<EOD
    Name: ${name}
    e-mail: 
    ${email}
    location: 
    ${location}
    EOD;

    //..... 
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    Aug 2009
    Posts
    4
    thanks for your reply

    I have figured out all but one problem
    I figured out how to get the PHP to send me all the required fields, and how to get the radio button values.

    Now the only problem i have is: I want to label the values in the responses i get in my inbox.

    For example right now i get:

    john smith

    105 cedar drive

    springfield, mass

    12345


    What i want:

    Name: John Smith
    Location: 105 cedar drive
    City & state: Springfield, mass
    Zip: 12345


    any help? please?



    thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles