Jump to content

Basic contact form help needed


autechre

Recommended Posts

Hi there PHP Freaks

 

I was wondering if anyone would be kind enough to help out with this coding for a basic contact form I am trying to create for my neighbour's website. Although I have some basic experience using HTML, I am a complete PHP newbie so I'm not sure where I'm going wrong. Please take a look at the following:

 

HTML as it appears on the page:

 

<form method="post" action="mailer.php" >

  <fieldset>

<legend>Contact Us</legend>

  <p>

Name: <br />

<input type="text" id="name" size="25" />

  </p>

  <p></p>

  <p>

Tel. no. (inc. area code): <br />

<input type="text" id="telephone" size="25" />

  </p>

  <p></p>

  <p>

E-mail: <br />

<input type="text" id="email" size="25" />

  </p>

  <p></p>

  <p>

Your message: <br />

<textarea name="message" rows="5" cols="50"></textarea>

  </p>

  <p></p>

  <p class="submit">

<input type="submit" value="Submit" />

  </p>

  </fieldset>

</form>

 

PHP as it appear in 'mailer.php':

 

<?php

  $name = $_REQUEST['name'] ;

  $telephone = $_REQUEST['telephone'] ;

  $email = $_REQUEST['email'] ;

  $message = $_REQUEST['message'] ;

 

  mail( "****@hotmail.co.uk", "Message from Website",

    $name, $telephone, $email, $message, "From: $email" );

  header( "Location: sendconfirm.html" );

?>

 

Please note, I have blanked the email address here, but basically the problem is that the message is not finding it's way to the email address. After the form is submitted, the page is re-directing to 'sendconfirm.html' so I think it is working to a certain extent except for the email not being received.

 

The website hosting package does support PHP scripting so that can't be the problem (unless the scripting support needs to be activated in some way, but I think that's unlikely).

 

Any help would be greatly appreciated.

 

Many thanks,

Daz

Link to comment
https://forums.phpfreaks.com/topic/204574-basic-contact-form-help-needed/
Share on other sites

You are using the mail function wrong. The format of the function is

<?php
mail($to,$subject,$body,$headers,$additional_headers);
?>

The $headers & $additional_headers parameters are optional, so in your case, do something like this:

<?php
  $name = $_POST['name'] ;
  $telephone = $_POST['telephone'] ;
  $email = $_POST['email'] ;
  $message = $name . "\n" . $telephone . "\n" . $_POST['message'] . "\n";

  mail( "****@hotmail.co.uk", "Message from Website", $message, "From: $name <$email>" );
  header( "Location: sendconfirm.html" );
?>

 

Ken

Rightio, using Ken's script above, it seems that progress is being made as an email is now coming through, however the only details being received are the main message body from the HTML form and the email subject title from the PHP script. The details entered in the name/telephone/email fields are not appearing anywhere in recieved email, also the 'From' part of the email is showing as 'unknown'.

 

Can anyone see where I'm going wrong? Any help is greatly appreciated.

 

Cheers,

Daz

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.