Email form not sending the from email address and message?

My email form isn’t emailing me two of the variables. The variables that I am not receiving are headers and message. Can someone please have a look at my php code, and tell me how I can solve the problem? Thanks in advance.


if ($error == '') {	
  					$to = "mail@domainname.com";
  					
  					$subject = "Message from website contact form";
  					
  					$headers = "From: ".$email."\
";
			
					$message = "Full Name: $yourname\
Phone Number: $phone\
Email: $email\
Nature: $nature\
Interested In: $interested\
Details: $details";
					
					mail($to, $subject, $message, $headers);

 					header("Location:sent.php");
 					exit;
 					
  				} else {
  					echo "<p><span>Please check the following errors:<br />";
       				echo "$error</span></p>";
    			}          

This one of the many fields in the form:

<input name="yourname" type="text" size="27" value="<?php if (isset($_POST['yourname'])) { echo $_POST['yourname']; } ?>" />

Replace $headers and $message with static strings that you can guarantee will work.

Once those are confirmed to be working, gradually replace them with the other variables until you find out what is causing it to fail.

Paul, could you please give me an example a static string? I don’t know much about php. The variable message is sending Full Name:, etc, but not the variables in message.

This is a dynamic string:


$str = 'A dynamic string due to ' . $someVar . ' is one that may not always be the same';

This is a static string:


$str = 'A static string is always the same, regardless of how other variables are set.';

Thanks for your help, Paul. I found out that it was silly mistake of not doing this $yourname = $_POST[‘yourname’]; for all of the variables. Sorry to waste your time, anyway I have learnt something about dynamic strings and static strings from you.