Jump to content

Help with code to complete script to send email from a form


Aloha

Recommended Posts

My name is Sarah. I am new to php. I found a sample php script I'd like to use which sends user-entered data from an HTML form to another page, which gets processed there with php. But I don't know how to also get the form results emailed to me. Here's what I mean:

Here's the HTML Form:

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post">
<select name="item">
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input name="quantity" type="text" />
<input type="submit" />
</form>
</body></html>

Here's the php processing the form:

<html><body>
<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];

echo "You ordered ". $quantity . " " . $item . ".<br />";
echo "Thank you for ordering from Tizag Art Supplies!";

?>
</body></html>

But I would also like to have the user entered data emailed to me. Can anyone help or show me how to do it?

Thank you,

Link to comment
Share on other sites

You're missing a bunch of code to make this anything that someone would actually want to fill out.  You don't even have anything that gathers the persons name, email, phone, etc.  You don't have any clue who is even filling out the form and wants stuff.  You're also wide open for XSS attacks, not that a beginner would be expected to know that kind of thing.  Check out this tutorial series to get you started.

http://www.youtube.com/playlist?list=PLF07A207A932D3997

Link to comment
Share on other sites

Try this for your mail requiremnt

<?php
$to      = 'nobody@example.com'; //set your email id
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Link to comment
Share on other sites

For mailing you must first gather the person information and then filling out the form and what order they want to do.

Below is the small example for email which may help you.

 

<?php 
$action
=$_REQUEST['action']; 
if (
$action=="")    /* display the contact form */ 
    

    
?> 
    <form  action="" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="action" value="submit"> 
    Your name:<br> 
    <input name="name" type="text" value="" size="30"/><br> 
    Your email:<br> 
    <input name="email" type="text" value="" size="30"/><br> 
    Your message:<br> 
    <textarea name="message" rows="7" cols="30"></textarea><br> 
    <input type="submit" value="Send email"/> 
    </form> 
    <?php 
    
}  
else                
/* send the submitted data */ 
    

    
$name=$_REQUEST['name']; 
    
$email=$_REQUEST['email']; 
    
$message=$_REQUEST['message']; 
    if ((
$name=="")||($email=="")||($message=="")) 
        { 
        echo 
"All fields are required, please fill <a href=\"\">the form</a> again."
        } 
    else{         
        
$from="From: $name<$email>\r\nReturn-path: $email"
        
$subject="Message sent using your contact form"
        
mail("youremail@yoursite.com"$subject$message$from); 
        echo 
"Email sent!"
        } 
    }   

?> 

Edited by priyankagound
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.