php mail form blues

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
so i've been checking out tutorials and i cant figure out whats wrong..

The Form
<form method="post" action="contact.php">
Contact **********
<br />
<input type="text" name="name" value="name" size="33" />
<br />
<input type="text" name="email" value="email" size="33" />
<br />
Mailing list subscription?
<input name="mailinglist" type="checkbox" value="mailinglist" checked />
<br />
<textarea name="message" rows="10" cols="30">message</textarea>
<br />
<input type="submit" value="submit" />
</form>


The PHP Page > Error is on line 27.. "Parse error: parse error, unexpected $ in...." It's where </HTML> is at. I dont understand what i didnt close.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cellar Door - Long Beach</title>
</head>

<body>
<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$mailinglist = $_REQUEST['mailinglist'] ;
$message = $_REQUEST['message'] ;

if (!isset($_REQUEST['email'])) {
    header( "Location: /not_sent.html" );
}
elseif (empty($email) || empty($message) ||empty($name)) {
    header( "Location: /not_sent.html" );
}
else {
    mail( "***@***.com", "***** Website Form",
    "$message\n\nDid they subcribe to the mailing list?? $mailinglist\n\n",
    "From: $name <$email>" );
    header( "Location: /sent.html" );
    ?>
    </body>
    </html>
 
you've not closed the } on the last else
 
thanks so much.

but now its

"Cannot modify header information - headers already sent by contact.php:8 on line 25"

grrr.. i tried blocking out the first if/else and it still says this.

Code:
<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$mailinglist = $_REQUEST['mailinglist'] ;
$message = $_REQUEST['message'] ;

//if (!isset($_REQUEST['email'])) {
//    header( "Location: /not_sent.html" );
//}
//else
if (empty($email) || empty($message) ||empty($name)) {
    header( "Location: /not_sent.html" );
}
else {
    mail( "**@**.com", "** Website Form",
    "$message\n\nDid they subcribe to the mailing list?? $mailinglist\n\n",
    "From: $name <$email>" );
    header( "Location: h/sent.html" );
}
    ?>
 
becuase it prcesses the page as it reads it, thus the html already sets the headers. put the html header code after the php code

or don't put any html in it at all, since you never see the page

or at the top of the page
put
PHP:
<?php
ob_start( 'ob_gzhandler' );
?>
which causes the page to be processed first and then displayed (and can speed up pages)
 
ohhh.. i overlooked that for sure.

what'd your paypal address. you just saved me endless man-hours!
 
I use an ASP sendmail script to connect to my mail server and I have the form page and the sendmail script in another file. Submit form to sendmail.asp and then redirect back to contact.asp.

I like to separate it this way.
 
grrr. it works but it isnt sending the mail.

i hate to do this but here is the form and revised (thank you) php.

Code:
<form method="post" action="contact.php">
Contact Cellar Door
<br />
<input type="text" name="name" value="name" size="33" />
<br />
<input type="text" name="email" value="email" size="33" />
<br />
Mailing list subscription?
<input name="mailinglist" type="checkbox" value="mailinglist" checked />
<br />
<textarea name="message" rows="10" cols="30">message</textarea>
<br />
<input type="submit" value="submit" />
</form>



Code:
<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$mailinglist = $_REQUEST['mailinglist'] ;
$message = $_REQUEST['message'] ;

if (empty($email) || empty($message) ||empty($name)) {
    header( "Location: not_sent.html" );
}
else {
    mail( "theEmailAddress@hotmail.com", "Cellar Door Website Form",
    "$message\n\nDid they subcribe to the mailing list?? $mailinglist\n\n",
    "From: $name <$email>" );
    header( "Location: sent.html" );
}
    ?>

(theEmailAddress@hotmail.com was added for privacy)
 
Last edited:
does it just fail sending the mail? i.e. is there an error returned from the mail command or just not delivering mail?. It looks ok technically, make sure the sever sendmail is configured and turned on
 
no errors. it goes to the "sent.html" as if everything was properly coded.

maybe my host turned it off? i've tried contacting them but they havent replied in over 8 months. -- hosting is only $12 a year. :/

warning: do not use webcountry.net!


thanks for your help Khayman.
 
it will go to sent.html if it goes or not

mail returns true or false depending if it work, try capturing that and checking it to see if it makes a difference. try different email addresses, make sure it spelt right ;)
 
what editor you are using for your work.
I mean what PHP editor

you have having very basic problems those can be removed by the good editor
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back