PHP e-mail

So this is a pretty simple problem. This code has worked for me before on other sites but all of a sudden it’s stopped working. I’m drawing the information through the form fields via global variables ( $_POST ) and that seems to work okay. When I input the information into the actual body of the email, that’s where my problem occurs. The email will send but none of the information will be in it. Dreamweaver says my syntax is fine but there’s an obvious problem because the emails are blank. Here’s the code:


<?php


$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];



$to = "shadow_slayer15@yahoo.com";

$body = 

<<<EOD
<br/><hr/><br/>
Name: $name<br/>
Email Address: $email<br/>
Subject: $subject<br/>
Message: $message<br/>
EOD;


$headers = "From: $email\\r\
";
$headers .= "Content-Type: text/html\\r\
";

$success = mail($to, $subject, $body, $headers);



$win =  <<<EOD

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<title>Thank You for Your Email</title>
</head>

<body>

<div id="header">
<h2>Craig Spector</h2>

<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="read.html">Read</a></li>
<li><a href="books.html">Books</a></li>
<li><a href="pov.html">POV</a></li>
<li><a href="av.html">A/V</a></li>
<li class="selected"><a href="contact">Contact</a></li>
</ul>

</nav>

<div id="head-gal">
<a href="http://www.facebook.com/craigspector"><img src="images/social-icons/facebook.png" width="100" height="100" alt="Facebook" /></a>
<a href="http://www.linkedin.com/in/craigspector"><img class="mid" src="images/social-icons/linkedin.png" width="100" height="100" alt="Linked In" /></a>
<a href="http://www.myspace.com/craigspector"><img class="left" src="images/social-icons/myspace.png" width="100" height="100" alt="Myspace" /></a>
</div><!-- end head-gal -->

</div><!-- end header -->

<div id="content">

<div id="inner-content">

<h2>Thank You for Contacting Me</h2>



<div class="padding"></div><!-- end padding -->

</div><!-- end inner content -->
</div><!-- end content -->



</body>
</html>



EOD;

echo $win;
?>


Your code does function, but can you post the contents of the PHP file that has the related form? My guess the problem is hiding there.

Try this:


$name = $_POST['name'] = "test name";
$email = $_POST['email'] = "webmaster@test.com";
$subject = $_POST['subject'] = "test subject";
$message = $_POST['message'] = "test message";

$to = "shadow_slayer15@yahoo.com";

$body = 
<<<EOD
<html>
<head>
  <title>test email</title>
</head>
<body>

<br/><hr/><br/>
Name: $name<br/>
Email Address: $email<br/>
Subject: $subject<br/>
Message: $message<br/>
</body>

</html>
EOD;

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\\r\
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\
";
$headers .= "From: $email\\r\
";



if (mail($to, $subject, $body, $headers))
{
	echo "sent";
}

It still sends a blank email. It says the email is sent by a long name .secureserver.net I don’t know if that means anything to anybody. I’m usually more of a designer but I have a base in PHP and this is killing me :sick:. The site is supposed to be live by the end of the week, I’m thinking of falling back on a WordPress plugin for the contact page until I can figure out what’s wrong with the site. Thank you for all the help everybody :slight_smile:

Unless you provide us with more information such as the script that contains the actual contact form, the website in question and even your web host, there is not much else we can do.

I used your script with hard-coded variables for the name, email, subject and it sent fine, so the problem is obviously elsewhere.

If you are dead set on a WP plugin for your contact form, ensure it does some type of data sanitation since your script has none so far.

I have same problem with shadow_slayer15.

I’m a complete newbie and still struggling with php and AS.

Here’s my case, i attached screen grab to give you gents a look of what i’ve been through.

Any enlightenment with my problem, would be appreciated.

Thanks in advance.