I am a novice at PHP, but I would like to create a simple form that sends to a single email upon Submit. I am running Apache and I don't get any errors, but I never receive my test emails? I press submit, and nothing. Can anybody tell me what I am doing wrong? Your help is greatly appreciated.

This is the code I have embedded in my contact_us.php file.

<form method="post" name="Emailform" action="sendmail.php" target="_self" onSubmit="onSubmit="return verify(this)">
<table border="0" cellspacing="0" cellpadding="4" width="90%" id="ContactMe"> 
<tr style="visibility:hidden">
    <td><input type="text" name="verify" size="20" value="" /></td>
</tr>
<tr> 
    <td width="30%"><div align="right">Name:</div></td> 
    <td width="70%"><input type="text" name="name" size="30" /></td> 
</tr> 
<tr> 
    <td><div align="right">Email:</div></td> 
    <td><input type="text" name="email" size="30" /></td> 
</tr> 
<tr> 
    <td><div align="right">Message:</div></td> 
    <td><textarea name="message" cols="40" rows="4"></textarea></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
    <td> 
    <input type="submit" name="submit" value="Submit" /> 
    <input type="reset" name="reset" value="Reset" /> 
    </td> 
</tr> 
</table>
</form>

Separate file named sendmail.php.

<?php
$to = "j.crnjarich@comcast.net";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$subject = "Message from: $name";
$message = $_REQUEST['message'] ;
$headers = "noreply@YOURWEBSITE.com";
$body = "From: $name \n\n Email: $email \n\n Wesbite: $site \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'contact_us.php';</script>";}
else
{echo "<script language=javascript>window.location = 'contact_us.php';</script>";}
?>

You cannot send mail from local servers for that you need a live server and its mail sending feature must be active.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.