Jump to content

PHP email form


mattrd

Recommended Posts

I can't seem to get my email form to work. yet it seems to work "sometimes" but not sure why, now i can't seem to get it to work at all. here is my code.

 

<?php $title="Contact Me"; ?>
<?php include("includes/header.php"); ?>
<?php 
if ($_POST["email"]<>'') { 
$ToEmail = 'MY-EMAIL-GOES-HERE; 
$EmailSubject = 'Website Contact Form'; 
$mailheader = "From: ".$_POST["name"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comments"])."<br>"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?> 
<div id="content">
	<h1>Contact.</h1>
	Your message was sent.
	<?php 
	} else { 

	echo "<div id=\"content\">
	<h1>Contact.</h1>
	<p>Please use the form below to send me an email. I'd love to hear from you!</p>
	<form action=\"contact.php\" method=\"post\">
		<label>Name:</label><br />
		<input class=\"text\" type=\"text\" name=\"name\" /><br />
		<label>Email Address:</label><br />
		<input class=\"text\" type=\"text\" name=\"email\" /><br />
		<label>Comments:</label><br />
		<textarea name=\"comments\" cols=\"60\" rows=\"5\" name=\"comments\"></textarea>
		<br />
		<input type=\"submit\" value=\"Submit\" />
	</form>;"
	?>
</div>
<?php 
}; 
?>
<?php include("includes/footer.php"); ?>

Any help will be greatly appreciated.

(form can be viewed here:) http://www.matthewrdaniels.com/contact.php

 

Thank you!

Link to comment
Share on other sites

Okay, I found out that most of the emails were going to my junk mail filter. But some didn't. Also, most of the emails show up under the name "Unknown Sender" while others show the name that was put into the name field. Any idea what could be causing that?  :shrug:

Link to comment
Share on other sites

    $yourname = "name";
    $youremail = "contact@website.co.uk";
    $subject = "you subject title";
    $body = "message you want to send"
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
    $headers = "From: $yourname<$youremail>\r\n";
    $headers .= "X-Mailer: PHP's mail() Function\n";


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

 

Try this

Link to comment
Share on other sites

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.