Jump to content

Recommended Posts

I'm having an absoloute nightmare trying to get an enquiry form to work on a website that I am designing. Firstly, let me point out I am a complete newbie with PHP so please pardon my ignorance on the subject, im a graphic designer not a programmer. The address for the page where the enquiry form is http://www.hairbykirbyblythe.co.uk/enquiries.html.

 

So far I am at a point where clicking the submit button correctly goes to the 'Thanks for your message' page, but no email is being received at all. Can someone please tell me what is wrong with my code?

 

This is the php on the enquiries page itself:

<?php
ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk ");
mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk');
?>
      <?php

ini_set('sendmail_from', $email_from); 
$email_to = "kirby@hairbykirbyblythe.co.uk";
$name =$_POST['Name'];
$email_from =$_POST['email']; 
$email_subject = "Enquiry";
$comments = $_POST['message'];
$headers = 
"From: $email_from .\n";
"Reply-To: $email_from .\n";

$message= "Name: ". $name  . "\ntelephone: " . $telephone; "\nemail: " . $email;

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');
if ($sent)
	{
		header( "Location: http://www.hairbykirbyblythe.co.uk" ); 
	} else {
		/* If there is an error display an error message */
		echo 'There has been an error sending your enquiry. Please try later.'; 
	}
?>

 

And my sendmail.php file is as follows:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
ini_set("sendmail_from", " [email]kirby@hairbykirbyblythe.co.uk[/email] ");
mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk');
?>
<?php

ini_set('sendmail_from', $email_from);
$email_to = "kirby@hairbykirbyblythe.co.uk";
$name =$_POST['Name'];
$email_from =$_POST['email'];
$email_subject = "Enquiry";
$comments = $_POST['message'];
$headers =
"From: $email_from .\n";
"Reply-To: $email_from .\n";

$message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email;

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');
if ($sent)
{
header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" );
} else {
/* If there is an error display an error message */
echo 'There has been an error sending your enquiry. Please try later.';
}
?>
</body>
</html>

 

The host of the account is Fasthosts on a Windows home package if this helps. All help and advice would be much appreciated. I've had this issue for months now and just want to get it sorted :(

Link to comment
https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/
Share on other sites

So do I need to remove all the HTML code from the sendmail.php file?

 

like so??:

 

<?php
ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk ");
mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk');
?>
<?php

ini_set('sendmail_from', $email_from);
$email_to = "kirby@hairbykirbyblythe.co.uk";
$name =$_POST['Name'];
$email_from =$_POST['email'];
$email_subject = "Enquiry";
$comments = $_POST['message'];
$headers =
"From: $email_from .\n";
"Reply-To: $email_from .\n";

$message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email;

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');
if ($sent)
{
header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" );
} else {
/* If there is an error display an error message */
echo 'There has been an error sending your enquiry. Please try later.';
}
?>

 

as i said, my knowledge is next to none on this - i do apologise

That doesn't look good, does it?

 

Notice: Undefined variable: email_to in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55

Notice: Undefined variable: email_subject in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55

Notice: Undefined variable: email_message in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55

Notice: Undefined variable: headers in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55

Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55

Notice: Undefined variable: email_from in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 59

Notice: Undefined index: Name in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 61

Notice: Undefined index: email in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 62

Notice: Undefined index: message in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 64

Notice: Undefined variable: telephone in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 69

Notice: Undefined variable: email in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 69

Warning: Cannot modify header information - headers already sent by (output started at \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php:59) in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 74

 

Well, your accessing these variables without initializing them.

 

That might be the cause, but I can't really tell because there seems to be some code missing.

<?php
ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk ");
mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk');
?>

Try this...

<?php
error_reporting(E_ALL ^ E_NOTICE);
$email_to = "kirby@hairbykirbyblythe.co.uk";
$name =$_POST['Name'];
$email_from =$_POST['email'];
$email_subject = "Enquiry";
$comments = $_POST['message'];
$headers ="From: $email_from\r\nReply-To: $email_from\r\n";

$message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email;

$sent = mail($email_to, $email_subject, $message, $headers);
if ($sent) {
  header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" );
} else {
  /* If there is an error display an error message */
  echo 'There has been an error sending your enquiry. Please try later.';
}
?>

You've got strict mode turned on - if you don't have access to php.ini to turn it off add this at the start of the script immediately after <?php

 

error_reporting(E_ALL ^ E_NOTICE);

but this only "cures" the symptoms ;)

 

There are no real serious symptoms here. All its saying is "these variables haven't been set" sort of thing. This is not serious and is nothing to worry about. The line I've specified to change the error reporting level will show anything that matters.

 

Not many servers I've come across are set up as strict.

Ok, thanks Yesideez - it is now at least sending me an email - although its a blank email with just the field names in (its progress at least :))

 

So here's where I'm at. The PHP on my enquiries (http://www.hairbykirbyblythe.co.uk/enquiries.php) page is:

 

<?php
ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk ");
mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk');
?>
      <?php

ini_set('sendmail_from', $email_from); 
$email_to = "kirby@hairbykirbyblythe.co.uk";
$name =$_POST['Name'];
$email_from =$_POST['email']; 
$email_subject = "Enquiry";
$comments = $_POST['message'];
$headers =
"From: $email_from .\n";
"Reply-To: $email_from .\n";

$message= "Name: ". $name . "\ntelephone: " . $telephone . "\nemail: " . $email . "\nenquiry: " . $nenquiry;

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');
if ($sent)
	{
		header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); 
	} else {
		/* If there is an error display an error message */
		echo 'There has been an error sending your enquiry. Please try later.'; 
	}
?> 

 

and my sendmail.php is:

 

<?php
error_reporting(E_ALL ^ E_NOTICE);
$email_to = "kirby@hairbykirbyblythe.co.uk";
$name =$_POST['Name'];
$email_from =$_POST['email'];
$email_subject = "Enquiry";
$comments = $_POST['message'];
$headers ="From: $email_from\r\nReply-To: $email_from\r\n";

$message= "Name: ". $name . "\ntelephone: " . $telephone . "\nemail: " . $email . "\nenquiry: " . $nenquiry;

$sent = mail($email_to, $email_subject, $message, $headers);
if ($sent) {
  header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" );
} else {
  /* If there is an error display an error message */
  echo 'There has been an error sending your enquiry. Please try later.';
}
?>

 

I'm sorry if it appears I haven't taken notice of what some people have said, thats not true - its just that I havent understood (as I said, I'm completely alien to all this). If you could just highlight the areas that are incorrect and let me know what I need to change them to I would be so grateful.

http://www.hairbykirbyblythe.co.uk/enquiries.php

 

this is the form where you can enter a message mail etc.... When you click submit, it'll go to sendmail.php in order to actually send the email, right? Ok, that being so, we don't need any mail() commands(or any other of the php you posted) on enquiries.php.

 

As for sendmail.php:

The name attributes of the input fields have been set incorrectly!

<label>Name:</label><p><input name="Name:" type="text" size="50" maxlength="50" /></p>

      <label>Telephone Number:</label> <p><input name="telephone" type="text" size="50" maxlength="20" /></p>
      <label>Email:</label><p><input name="email" type="text" size="50" maxlength="25" /></p>
      <label>Enquiry:</label><p><textarea name="enquiry" cols="90" rows="12"></textarea></p>

 

should rather be:

<label>Name:</label><p><input name="name" type="text" size="50" maxlength="50" /></p>
      <label>Telephone Number:</label> <p><input name="telephone" type="text" size="50" maxlength="20" /></p>
      <label>Email:</label><p><input name="email" type="text" size="50" maxlength="25" /></p>
      <label>Enquiry:</label><p><textarea name="message" cols="90" rows="12"></textarea></p>

 

When you submit a form using the post method(that's what you do: <form action="sendmail.php" method="post">) - all the data from the form is collected in the array $_POST

You can access the values again by using $_POST['nameOfTheFieldGoesHere']

 

This is how you tried to access the data:

<?php
$name =$_POST['Name'];
$email_from =$_POST['email']; 
$email_subject = "Enquiry";
$comments = $_POST['message'];
?>

As you can see, only 'email' matches the name specified in enquiries.php(name="email")

I recommend you to name the input fields always in the same manner. This reduces the error rate.

 

If you use this instead, it should work:

<?php
error_reporting(E_ALL ^ E_NOTICE);
$email_to      = "kirby@hairbykirbyblythe.co.uk";
$name          = $_POST['name'];
$email_from    = $_POST['email'];
$comments      = $_POST['message'];
$telephone     = $_POST['telephone'];
$email_subject = "Enquiry";
$headers       = "From: $email_from\r\nReply-To: $email_from\r\n";
$message       = "Name: "        .$name 
                 ."\ntelephone: ".$telephone
                 ."\nemail: "    .$email 
                 ."\nenquiry: "  .$comments;

$sent = mail($email_to, $email_subject, $message, $headers);
if ($sent) {
  header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" );
} else {
  /* If there is an error display an error message */
  echo 'There has been an error sending your enquiry. Please try later.';
}
?>

 

Thank you so much for your advice phant0m. Just one minor problem now, It's sending me the email with all the info from the form except the 'email' field is not sending the information

 

any ideas?

 

<?php
error_reporting(E_ALL ^ E_NOTICE);
$email_to      = "kirby@hairbykirbyblythe.co.uk";
$name          = $_POST['name'];
$email_from    = $_POST['email'];
$comments      = $_POST['message'];
$telephone     = $_POST['telephone'];
$email_subject = "Enquiry";
$headers       = "From: $email_from\r\nReply-To: $email_from\r\n";
$message       = "Name: "        .$name 
                 ."\ntelephone: ".$telephone
                 ."\nemail: "    .$email 
                 ."\nenquiry: "  .$comments;

$sent = mail($email_to, $email_subject, $message, $headers);
if ($sent) {
  header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" );
} else {
  /* If there is an error display an error message */
  echo 'There has been an error sending your enquiry. Please try later.';
}
?>

Thank you all so much for your help. This thing has been a nightmare for me as Im just a graphic designer. You've all been fantastic.

 

just finally, is there a simple bit of code to put in that could just prompt the user if they were to enter an invalid email address?

 

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.