Form submit nightmare

Hi,

Im trying to submit the email through the online contact page http://www.origin-designs.co.uk/. I cannot receive emails through it, im not sure where is the problem with the code. It seems to be working fine for other people through fiddle or some other tool. I’m providing the code for the form too. any feedback welcome, cheers

PHP code: [php]<?php
$error = false;
$sent = false;

	if(isset($_Post['name'])) {
		if(empty($_Post['name']) || empty($_Post['email']) || empty($_Post['comments'])) {
			$error = true;
		} else {
		
		$to = "[email protected]";
		
		$name = trim($_Post['name']);
		$email = trim($_Post['email']);
		$comments = trim($_Post['comments']);
		
		$subject = "Contact Form";
		
		$messages =  "Name: $name \r\n Email: $email \r\n Comments: $comments";
		$headers = "From:" . $name;
		$mailsent = mail($to, $subject, $messages, $headers);
		
		if($mailsent) {
			$sent = true;
		}
	}
}

?>[/php]

HTML: <?php if($error == true) { ?> <p class="error"></p> <?php } if($sent == true) { ?> <p class="sent"></p> <?php } ?> <div id="form"> <form name="contact" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, "utf-8"); ?>" method="post"> <fieldset> <h4>Contact Me!</h4> <label for="name">Name:</label> <input type="text" name="name" id="name"/> <label for="email"/>Email:</label> <input type="text" name="email" id="email"/> <label for="comments" id="comments">Comments:</label> <textarea name="comments" id="" width="90%"></textarea> <fieldset> <input class="btn" type="submit" name="submit" class="submit" value="Send email"/> <input class="btn" type="reset" value="Reset"/> </fieldset> </fieldset> </form>

Many thanks

All _Post change to caps

[php]$_Post[/php]

[php]$_POST[/php]

$_REQUEST is even safer than $_POST because it will also pickup $_GET variables.

Hi,

Your headers seems to be missing some other information. Try this:

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= “From:” . $name . “\r\n”;

$mailsent = mail($to, $subject, $messages, $headers);

It works for me. Good luck!

Regards,
developer.dex2908

Hi dex2908,

I tried your approach and it worked fine, thank you for that, apart from one little nuance. Basically it is displaying some odd (text/[email protected]) email address instead of senders email. What could be the issue with that one? I tried to change $headers content-type value to email and some other options, it did not work out.

Cheers

Strange it had nothing to do with the post var not being correct as this would not work as $_Post is not the same as $_POST.

[php]$headers = “From:” . $name.’<’.$email.’>’;[/php]

Hi,

It seems like your $name variable has incorrect value. Do a var_dump on the variable. If it has no problem, perhaps there is something wrong with the syntax.

Good luck!

Regards,
developer.dex2908

Thank you both.

solved then ?

am at work now cannot FTP the thing. Cheers

Sponsor our Newsletter | Privacy Policy | Terms of Service