# Problem with PHP Mail Form

**URL:** <https://forum.kirupa.com/t/problem-with-php-mail-form/283025>\
**Category:** programming\
**Created:** [March 1, 2009, 7:11pm UTC](https://forum.kirupa.com/t/problem-with-php-mail-form/283025 "2009-03-01T19:11:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harpo64](https://avatars.discourse-cdn.com/v4/letter/h/ee59a6/32.png) [@harpo64](https://forum.kirupa.com/u/harpo64)\
**Post date:** [March 1, 2009, 7:11pm UTC](https://forum.kirupa.com/t/problem-with-php-mail-form/283025/1 "2009-03-01T19:11:10Z")

</div>

This has been driving me crazy for a week now. I’ve set up many forms using PHP to gather and send data, but I have one now that isn’t working and I can’t get it to work. I tried using the most basic tutorial here [http://www.kirupa.com/web/php\_contact\_form.htm](http://www.kirupa.com/web/php_contact_form.htm) in addition to several others. What happens is that everything acts like it’s working, I get the success message, but no mail ever goes through. I’ve tried this with my e-mail addresses and client e-mails and the result is the same. Are there any suggestions as to what may cause this? I’m running PHP 4, switched back from 5 in case that was the problem, but no change.

Here’s the latest stripped down code I’m trying, with my e-mail address removed.

\*\*Form:  
\*\*  
\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)”\>  
\<html xmlns=“[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)”\>  
\<head\>\</head\>

\<form method=“post” action=“mailer.php” \>  
\<p\>We’re always interested in feedback or suggestions. Use this form to send us your thoughts and ideas.\<br /\>  
\<br /\>  
\<strong\>Name\</strong\>\<br /\>  
\<input type=“text” name=“name” size=“25” /\>  
\<br /\>  
\<b\>\<strong\>Email address\</strong\>\</b\>\<br /\>  
\<input type=“text” name=“email” size=“25” /\>  
\<br /\>  
\</p\>  
\<hr size=“4” noshade=“noshade” /\>  
\<br /\>  
\<font face=“Century Gothic” size=“3”\> \<b\>\<strong\>Any Comments or Suggestions?\</strong\> \<br /\>  
\</b\>  
\<textarea name=“message” rows=“6” cols=“45” wrap=“soft”\>  
\</textarea\>  
\<br /\>  
\<br /\>  
\<input type=“submit” name=“submit” value=“submit” /\>  
\<br /\>  
\<br /\>  
\<font size=“1”\>Hit the ‘back’ button on your browser to return from your confirmation page.\</font\>\</font\>  
\</form\>

\</body\>  
\</html\>

**PHP script**

\<?php  
if(isset($\_POST[‘submit’])) {  
$to = “(email removed for privacy)”;  
$subject = “Contact Us Message”;  
$name\_field = $\_POST[‘name’];  
$email\_field = $\_POST[‘email’];  
$message\_field = $\_POST[‘message’];

$body = “From: $name\_field  
E-Mail: $email\_field  
Message:  
$message”;

echo “Data has been submitted to $to!”;  
mail($to, $subject, $body);  
} else {  
echo “There was an error sending data, please go back and try again.”;  
}  
?\>

Thanks in advance for any ideas or suggestions
