Jump to content

Recommended Posts

Please check the following:

 

THE FORM:

 

<div id="content" style="height:440px; padding-top: 50px;">

<form action="formmail.php" method="post" id="enquiryform">

<fieldset style="width: 300px; padding-top: 8px; margin-bottom: 0px; margin-left:87px; padding-bottom:20px">

<legend>Your contact details</legend>

<p style="width:300px;">

<label for="name">Name:</label>

<input type="text" name="name" id="name" tabindex="1" />

</p>

<p style="width:300px;">

<label for="email">Email:</label>

<input type="text" name="email" id="email" tabindex="2" />

</p>

<p style="width:300px;">

<label for="telephone">Telephone:</label>

<input type="text" name="telephone" id="telephone" tabindex="3" />

</p>

</fieldset>

<fieldset style="width: 300px; padding-top: 0px; margin-left:87px; padding-bottom:20px">

<legend>Comments</legend>

<p style="width:300px;">

<label for="message">Message:</label>

<textarea name="message" id="message" rows="10" cols="20" tabindex="4"></textarea>

</p>

</fieldset>

<input class="button" type='submit' value='Submit' style="margin-left:300px;" />

</form>

</div>

 

THE PHP SCRIPT:

 

<?php

 

/* Incoming Subject and Email Variables - Fixed */

 

$emailSubject = 'Message';

$webMaster = 'joebloggs@hotmail.com';

 

/* Gathering Data Variables - User Data */

 

$name = $_POST['name'];

$email = $_POST['email'];

$telephone = $_POST['telephone'];

$message = $_POST['message'];

 

$body = <<<EOD

<br><hr><br>

Email: $email <br>

Name: $name <br>

Telephone: $telephone <br>

Comments: $message <br>

EOD;

 

$headers = "From: $email\r\n";

$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

 

/* Results rendered as code */

 

$theResults = <<<EOD

Removed for this post (too much data to post)

EOD;

echo "$theResults"

 

 

?>

 

 

You can see the form at www.beechhillsafety.co.uk.  The data gets sent off, the thank you page appears, but nothing arrives at my mail box.  This is stranmge as it worked for ages and now does nothing; could it be a problem with the server host?

 

Thanks in advance for any help.

<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
/* Incoming Subject and Email Variables - Fixed */

   $emailSubject = 'Message';
   $webMaster = 'joebloggs@hotmail.com';

/* Gathering Data Variables and checks if valid - User Data */

   $name = $_POST['name'];
   $email = $_POST['email'];
   $telephone = $_POST['telephone'];
   $message = $_POST['message'];
   
   if(!preg_match("^/[a-z0-9]$/i", $name)){
$msg = "Name did contain illegal characters";
   } elseif(!preg_match("/^.+@.+\..+$/", $email)){
$msg = "Email is not valid";	
   }else {
   
   $body = "<br><hr><br>
Email: $email <br>
Name: $name <br>
Telephone: $telephone <br>
Comments: $message";

   $headers = "From: $email\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($webMaster, $emailSubject, $body, $headers);
   if($success){
   $msg = "Mail have been sended";
   }
   
/* Shows the message/error */

if($msg){
echo $msg; 
}

}
}
      

?>

<div id="content" style="height:440px; padding-top: 50px;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="enquiryform">
<fieldset style="width: 300px; padding-top: 8px; margin-bottom: 0px; margin-left:87px; padding-bottom:20px">
<legend>Your contact details</legend>
<p style="width:300px;">
   <label for="name">Name:</label>
   <input type="text" name="name" id="name" tabindex="1" />
</p>
<p style="width:300px;">
   <label for="email">Email:</label>
   <input type="text" name="email" id="email" tabindex="2" />
</p>
<p style="width:300px;">
   <label for="telephone">Telephone:</label>
   <input type="text" name="telephone" id="telephone" tabindex="3" />
</p>
</fieldset>
<fieldset style="width: 300px; padding-top: 0px; margin-left:87px; padding-bottom:20px">
<legend>Comments</legend>
<p style="width:300px;">
<label for="message">Message:</label>
<textarea name="message" id="message" rows="10" cols="20" tabindex="4"></textarea>
</p>
</fieldset>
<input class="button" type='submit' value='Submit' style="margin-left:300px;" />
</form>
</div>

 

I adjusted the code abit and made it more secure.

Thanks for the reply.  However, I am trying to keep the following included to display the thankyou html.

 

/* Results rendered as code */

$theResults = <<<EOD

Removed for this post (this is the HTML that will display)

EOD;

echo "$theResults";

 

I got this code from 

http://www.tutvid.com/tutorials/dreamweaver/tutorials/phpFormHandler.php

 

Everything seems to be coded correctly.  I am baffled.

 

 

 

 

The PHP mail() function returns a boolean value. Capture the returned result in a variable and see what it is. At least knowing what value the function is returning is a step in the right direction.

 

<?php
$to = "email@example.com";
$subject = "Testing the form";
$message = "Hello World.";
$bool = mail($to, $subject, $message);
echo $bool;
?>

 

Also, if you wrap your posted code in the code tags (click the pound sign on the formatting toolbar), it will display better for the rest of us.

The PHP mail() function returns a boolean value. Capture the returned result in a variable and see what it is. At least knowing what value the function is returning is a step in the right direction.

 

<?php
$to = "email@example.com";
$subject = "Testing the form";
$message = "Hello World.";
$bool = mail($to, $subject, $message);
echo $bool;
?>

 

Also, if you wrap your posted code in the code tags (click the pound sign on the formatting toolbar), it will display better for the rest of us.

don't forget the $header else the mail will arrive at spam  ;)

~Blaatschaap

Put this at the top of the page, make sure that the page WON'T forward when you submit the form, and check to see if all the information that is being submitted is actually being fed to the page.

 

This will show you everything in the POST array.

<?php
print_r($_POST);
?>

Correction:

 

Have received two Hello World emails to my work address

 

Have received nothing from hotmail...(even though it was working perfectly well a couple of weeks ago)

 

A big clue I think...

well maybe it isn't..

perhaps server where you run it at got blocked by hotmail.

this will happend quite quickly if you send rapid emails  ;)

 

try gmail.com

 

~Blaatschaap

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.