• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

php mail form blues

#1
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>
 
#4
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" );
}
    ?>
 

Khayman

I'm sorry Hal...
Political User
#5
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)
 

Admiral Michael

Michaelsoft Systems CEO
#7
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.
 
#8
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:

Khayman

I'm sorry Hal...
Political User
#9
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
 
#10
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.
 

Khayman

I'm sorry Hal...
Political User
#11
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 ;)
 

loanskey

OSNN One Post Wonder
#15
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,960
Messages
673,237
Members
89,011
Latest member
grovo_test