...

View Full Version : mail() form not working



chilipie
03-20-2007, 05:13 PM
I have an email form from way back, but in editing it I've somehow managed to break it. Here's what I've got:


<?php

if(isset($contact))
{

if(!empty($_POST['name']) and !empty($_POST['email']) and !empty($_POST['subject']) and !empty($_POST['message']))
{

mail("ollie@chilipie.co.uk", "BM Contact Form: ".$_POST['subject'], $_POST['message'], "From: ".$_POST['name']." <".$_POST['email'].">\r\n") or die("Sorry, but the form isn't working at the moment. Please try again later.");

header("refresh: 0; url=contact.php?form=done");

} else {

die(header("refresh: 0; url=contact.php?form=error"));

}
}

?>

And then below it, in the body of the page:


<?php

if($_GET['form'] == 'done')
{
echo "<p>Thank you, your message has been sent successfully. We will endeavour to reply as soon as possible.</p>";
}

if($_GET['form'] == 'error')
{
echo "<p>Uh-oh! Please check that all fields in the form were filled in and try again.</p>";
}

?>

<form action="contact.php" method="post">

<label for="form-name">Name</label>
<input type="text" name="name" id="form-name" size="30" />

<label for="form-email">Email</label>
<input type="text" name="email" id="form-email" size="30" />

<label for="form-subject">Subject</label>
<input type="text" name="subject" id="form-subject" size="30" />

<label for="form-message">Message</label>
<textarea name="message" id="form-message" cols="60" rows="10"></textarea>

<input type="submit" name="contact" />

</form>

I'm not getting returned any errors - it just doesn't seem to do anything apart from load contact.php again. It's probably something ridiculously easy to fix, but I'm just lost because of the lack of any error messages.

Thanks
Ollie

ltabdiel
03-20-2007, 05:21 PM
try this:


<?php

if(isset($contact))
{

if(!empty($_POST['name']) and !empty($_POST['email']) and !empty($_POST['subject']) and !empty($_POST['message']))
{

mail("ollie@chilipie.co.uk", "BM Contact Form: ".$_POST['subject'], $_POST['message'], "From: ".$_POST['name']." <".$_POST['email'].">\r\n") or die("Sorry, but the form isn't working at the moment. Please try again later.");

header("refresh: 0; url=contact.php?form=done");

} else {

header("refresh: 0; url=contact.php?form=error");

}
}

?>

chilipie
03-20-2007, 05:31 PM
Thanks, but it does exactly the same as before - just loads up contact.php.

ltabdiel
03-20-2007, 05:35 PM
nothings triggering $contact i think

Nightfire
03-20-2007, 05:40 PM
<?php
if(isset($_POST['contact'])){

chilipie
03-20-2007, 05:58 PM
Heh, it just had to be something that stupid :o

Thanks very much guys :)

chilipie
03-20-2007, 06:16 PM
Just one more thing... :rolleyes:

What would be the correct way to go about doing this?


$message="$_POST['business']\n$_POST['phone']\n$_POST['description']";

Basically those three vars with a line break in between.

Nightfire
03-20-2007, 06:18 PM
$message = $_POST['business'] ."\n".$_POST['phone']."\n".$_POST['description'];

That's the way I'd do it

goughy000
03-20-2007, 11:59 PM
$message = $_POST['business'] ."\n".$_POST['phone']."\n".$_POST['description'];

That's the way I'd do it

or \r in it too just incase



$message = $_POST['business'] ."\r\n".$_POST['phone']."\r\n".$_POST['description'];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum