Log in

View Full Version : php mail form



cyndie
08-24-2007, 04:33 PM
I have forms on a website that I want my php to return information in the email.
Here is the php:

<?php

$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$date = $_REQUEST['date'] ;
$comments = $_REQUEST['comments'] ;

if (!isset($_REQUEST['email'])) {
header( "Location: http://www.c1realty.com/temp/pm/mreq.htm" );
}

elseif (empty($name) || empty($phone) || empty($date) || empty($email)) {
header( "Location: http://www.c1realty.com/temp/error.htm");
}


else {
mail( "info@c1realty.com", "Web Maintenance Request Form",
$comments, "From: $name <$email>" );
header( "Location: http://www.c1realty.com/temp/thanks.htm" );
}

?>

When the email is sent to the mailbox of info@c1realty.com I want it to also include the comments, phone number, date so this information is supplied in the email.

I can get it to work using $comments, or $phone, or $date, but I cannot get it to work if I combine them for instance
$comments, $phone, $date, "From: $name <$email>" );

I know there must be a way to do this, but I have not been able to figure it out. Can someone help?

Thanks
cyndie

boogyman
08-24-2007, 05:34 PM
<?php

$to = "info@c1realty.com";
$subject = "Web Maintenance Request Form";
$message = "";
$from = trim(strip_tags($_REQUEST['email']));

foreach($_REQUEST as $key => $val)
{
$message .= $key .": ". trim(strip_tags($val)) ."\n";
}

if( !mail($to, $subject, $message, "From: $from") {
header("Location: http://www.c1realty.com/temp/error.htm");
}
else {
header("Location: http://www.c1realty.com/temp/thanks.htm");
?>


that will populate the "body" of the email with everything that has been sent via the form...

cyndie
08-24-2007, 06:05 PM
Thanks I'll try this.
Cyndie

cyndie
08-24-2007, 06:39 PM
Thanks for the response boogeyman. however when testing on my server it does not redirect to the Thank you page and never sends the email.

Is there something in this php file I need to edit?

boogyman
08-24-2007, 08:43 PM
if( !mail($to, $subject, $message, "From: $from") {
...
}
else {
...


lovely typo's


if( !mail($to, $subject, $message, "From: $from") ) {
...
}
else {
...
}

cyndie
08-25-2007, 01:31 PM
Thanks Boogyman, works like a charm!