• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Creating a PHP email contact form?


#1
Hi Guys,

I need to make a page of a website with a form and then the form details emailed to someone.

I believe that there is no way to do this via CSS & HTML alone, is this correct?

I do not know php at all, although I have given this a bash via a coding book I have, but it does not seem to work.

Can someone tell me what I have done wrong or help me in any way as I am starting to get frustrated?

Cheers

Sarah

Code:-

<?php
if (array_key_exists('Notify', $_POST)) {
$to = 'notify@got-the-concept.co.uk';
$subject = 'Notify when Live';
$expected = array('Name', 'Email Address');
$required = array('Name', 'Email Address');
$headers = 'From: My website<notify@got-the-concept.co.uk>';
$process = 'process_mail.inc.php';
if (file_exists($process) && is_readable($process)) {
include($process);
}
else {
$mailSent = false;
mail($to, 'Server Problem', "$process cannot be read", $headers);
}
}
?>
<?php
if ($POST && isset($missing) && (!empty($missing)) {
?>
<p class="warning"> Not all required fields were filled in. </p>
<?php
}else if ($POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message. Please try later. </p>
<?php
}
elseif ($POST && $mailSent) {
?>
<p> <strong>Your message has been sent. Thank you for your feedback. </strong> </p>
<?php } ?>
<form action="<?php echo $_SERVER['PHP SELF']; ?>" method="post">
<input type="hidden" name="subject" value="notify me from site" />
<input type="hidden" name="redirect" value="http://www.got-the-concept.co.uk/notify2.html" />
<p> <strong> Name </strong> </p> <br /> <input type="text" name="Name" size="30" />
<p> <strong> Email Address </strong> </p> <br /> <input type="text" name="Email Address" size="30" />
<p> <input type="button" name="Notify" value="Notify" /> </p>
</form>
 

gwebhostuk

Junior Member
#3
HTML Form :

<form name="form1" method="get" action="sendmail.php">

<input name="yourname" class="input-bx" value="Your Name" onClick="this.value=''" type="text" />

<input name="youremail" class="input-bx" value="Your email" onClick="this.value=''" type="text" />

<input type="submit" name="Submit" value=" " class="submitclass" />

</form>

PHP code :


<?php
$emailid = $_GET["youremail"];
$yourname = $_GET["yourname"];


if($emailid!="")
{



$to = "receiver email id";

$subject = "subject here";

$mailbody_client = "message text here";

$headers = "Content-type: text/html; charset=iso-8859-1";
@mail($to, $subject, $mailbody_client, $headers);

header("Location: thanks.html");
exit;
}
?>
 

Jazajay

Active Member
#4
I have a feeling the one Alex L points to will do the job plus a lot more. It's pretty intensive. Literally copy, paste, change bold areas job done. :)