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 - email@me.com
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.

http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/

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.

Cheers
Nicolas.

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?

product.php?Item-26

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.

<?php
// Website variables
$sitefrom = "info@mydomin.com"; // Website email address for sending email
$sitename = "My cool product site"; // Website name
$to = "myemail@myemail.com"; //Where email should be sent to

if(isset($_POST['sendinfo'])):
    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);    
    }else{
        $emessage = '<span style="color:red;">Please add name and email address</span>';
    }
endif;

?>
<html>
<body>
<?php
//sample data grabbed from GET/mysql query
$prod_id = "22";
$prod_name = "My Product";
?>

<?php
// error message
if(isset($emessage)){ echo $emessage; }
?>
<form method="post" action="">
<p>
    <label for="naam">Name:</label>
    <input type="text" name="name" id="name" size="30" />
</p>
<p>
    <label for="email">E-mail:</label>
    <input type="text" name="email" id="email" size="30" />
</p>
    <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" /> 
</p>
</form>
</body>
</html>

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