Jump to content

mail.php


kev_77

Recommended Posts

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 = ' [email protected]';

$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

Link to comment
https://forums.phpfreaks.com/topic/41626-mailphp/
Share on other sites

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 = ' [email protected]';
$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

Link to comment
https://forums.phpfreaks.com/topic/41626-mailphp/#findComment-201685
Share on other sites

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 = ' [email protected]';
$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

Link to comment
https://forums.phpfreaks.com/topic/41626-mailphp/#findComment-201694
Share on other sites

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 = "[email protected]"; //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

Link to comment
https://forums.phpfreaks.com/topic/41626-mailphp/#findComment-201759
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.