kev_77 Posted March 7, 2007 Share Posted March 7, 2007 I realise this may have been covered many times before but I am very new to php and can't seem to find what I am looking for in the forum. Basically I am calling mail.php from my form. The form is very simple and has only 4 fields, Name, Email, Telephone and Comments. My hosting company sent me the following mail.php to use but I don't know how to include the form fields: <? $to = ' me@mydomain.com'; $subject = 'Web Enquiry'; $message = 'From: ' . $_REQUEST['Name'] . "\n\n" . $_REQUEST['Comments']; $email = $_REQUEST['Email']; $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail ($to, $subject, $message, $headers); header("Location: index.htm"); ?> Once submitted (obviously changing the e-mail address) I duly receive an e-mail containing from, Name and comments. How do I add further fields such as Telephone etc? Also, the redirect doesn't work? I was told that after submission, the user would be redirected to the home page? Your answers are much appreciated Kevin Quote Link to comment Share on other sites More sharing options...
EagerWolf Posted March 7, 2007 Share Posted March 7, 2007 create 2 files: First file: Forms for data to be inserted... <form method="post" action="mail.php"> ... </form> This will call function mail.php when form is submitted... Second file (mail.php): $to = ' me@mydomain.com'; $subject = 'Web Enquiry'; $message = 'From: ' . $_REQUEST['Name'] . "\n\n" . $_REQUEST['Comments']; $email = $_REQUEST['Email']; $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail ($to, $subject, $message, $headers); header("Location: index.htm"); $example_from_form = $_post['name']; Example_from_form will check what is inserted in form field named 'name'... That is the way you can use your file ... I hope it help if not ... ask Quote Link to comment Share on other sites More sharing options...
kev_77 Posted March 7, 2007 Author Share Posted March 7, 2007 Thanks for the reply, as I said initially, I am very new to this and don't quite understand your answer. Are you saying all I need to do is enter the line, $example_from_form = $_post['name']; and it will populate the mail I receive? $to = ' me@mydomain.com'; $subject = 'Web Enquiry'; $message = 'From: ' . $_REQUEST['Name'] . "\n\n" . $_REQUEST['Comments']; $email = $_REQUEST['Email']; $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $example_from_form = $_post['myform']; mail ($to, $subject, $message, $headers); header("Location: index.htm"); Also, what about the redirect? Sorry if these questions appear a little "green". Regards Kevin Quote Link to comment Share on other sites More sharing options...
kev_77 Posted March 7, 2007 Author Share Posted March 7, 2007 OK trawled the forums and cobbled this answer together which works almost exactly as I need. The only thing that doesn't work is the redirect at the end of the file: <?php $email_address = "me@mydomain.com"; //need to change to your address $subject = "Contact from Website"; $name = $_POST['Name']; $email = $_POST['Email']; $telephone = $_POST['Telephone']; $comments = $_POST['Comments']; $message ="Contact Name:".$name."\n\nEmail-Address:".$email."\n\nTelephone:".$telephone."\n\nComments:".$comments; mail($toname."<".$email_address.">",$subject,$message,"From: ".$name."<".$email.">"); //Redirects to index.htm header("Location: index.htm") ?> Any ideas? Regards Kevin Quote Link to comment Share on other sites More sharing options...
interpim Posted March 7, 2007 Share Posted March 7, 2007 change index.htm in the line below to where you want it to redirect to... then, close the statement with a semicolon header("Location: index.htm"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.