Sending a from with data

Basically what I am needing is when a visitor comes to my site and request info on a product, the form sends the product id or name.

I have the site set up like product.php?Item-26 and the item number changes based on the product.

I need the email being sent to say something like

Visitors Name has requested info on Item 26

Name - Visitors Name
Email -
Phone - 123-456-7890
Company - Visitors Company

Item info requested for
Here is the products name

I have searched everywhere and I cannot find anywhere that I can make this happen. Having a form pull data from the database.

Any help would be greatly appreciated

Do you know any PHP and mySQL?

Very little, I am just now learning it. I know enough to edit it but not write it from scratch.

I followed a tutorial and used the code I found, but I dont know how to get it to send the data.

I used this code.

Hello laflair13,
unfortunatly, this code has no connection with a database.
It just send a specific mail with the data entered in the form during the submit.


I understand that, I am trying to figure out how I can add data to it.

I guess in the URL address shold end with “?Item=26”/ And the PHP program will receive that value from the superglobal vaiable $_GET[‘Item’]

Can you point me in the right direction to learn how to do it?

Start with the Simple Tutorial.

How are currently displaying data when an item is requested? Do you have a product page with named items?


It seems you already MIGHT already have the data you are looking for.

I am using php/mysql to pull the data from the database and displaying it on the page. I need to know how to show the data in an email using a form.

Load the data into hidden fields in the form and then it will get passed as part of the form data.

Very basic example… assuming this is the product detail page with prod_id and prod_name.

// Website variables
$sitefrom = ""; // Website email address for sending email
$sitename = "My cool product site"; // Website name
$to = ""; //Where email should be sent to

    if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) && !empty($_POST['name'])){ 
        $subject = $sitename . " Contact Form Subject: I am interested in " . $_POST['prod_name'];
        // Build email message
        $message = "I am interested in learning more about " . $_POST['prod_name'] . "\nProduct ID: " . $_POST['prod_id'];        
        $message .= "\n\nFrom: {$_POST['name']}\nEmail:  {$_POST['email']}\n"; 
        $headers = "MIME-Version: 1.0\n"; 
        $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
        $headers .= "Content-Transfer-Encoding: 8bit\n";      
        $headers .= "From: $sitename <$sitefrom>\n"; 
        $headers .= "Reply-To: {$_POST['name']} <{$_POST['email']}>\n"; 
        $headers .= "X-Priority: 1\n"; 
        $headers .= "X-MSMail-Priority: High\n"; 
        $headers .= "X-Mailer: PHP/" . phpversion()."\n"; 
        mail($to, $subject, $message, $headers);    
        $emessage = '<span style="color:red;">Please add name and email address</span>';

//sample data grabbed from GET/mysql query
$prod_id = "22";
$prod_name = "My Product";

// error message
if(isset($emessage)){ echo $emessage; }
<form method="post" action="">
    <label for="naam">Name:</label>
    <input type="text" name="name" id="name" size="30" />
    <label for="email">E-mail:</label>
    <input type="text" name="email" id="email" size="30" />
    <input type="hidden" name="prod_id" value="<?php echo $prod_id;?>" />
    <input type="hidden" name="prod_name" value="<?php echo $prod_name;?>" />
    <input type="submit" name="sendinfo" value="Send Info" /> 

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.