Page 1 of 2

PHP Form Help

Posted: Thu Jun 08, 2006 4:00 am
by gkw
Hi im new here and ive got a question I need answering.

Ive recently created a php form but when I click submit I never recieve an email. After viewing other sites and tutorials I have the following code.

<?
mail( "bookings@gfunk-online.co.uk", "Feedback Form Results",
$message, "From: $email", "-yourname@yourdomain.com" );
header( "Location: http://www.gfunk-online.co.uk/confirmation.html" );
?>


I found out I have to put the code 'ini_set ("sendmail_from", "bookings@gfunk-online.co.uk")' in somewhere but I dont know where. If I put it before the code above I get an error message;

ini_set ("sendmail_from", "bookings@gfunk-online.co.uk")
Warning: Cannot modify header information - headers already sent by (output started at e:\domains\g\gfunk-online.co.uk\user\htdocs\sendmail.php:3) in e:\domains\g\gfunk-online.co.uk\user\htdocs\sendmail.php on line 6

Can anyone help me please?

Thanks

Posted: Thu Jun 08, 2006 4:18 am
by ok
This would work (i don't know if it's allowed sending header after mail()...):

Code: Select all

$headers = 'From: '. $email. "\r\n";
$check = mail("bookings@gfunk-online.co.uk", "Feedback Form Results", $message, $headers);
if($check == TRUE)
{
	echo "Successfully sent! you can now check your email(".$to.")!";
}else{
	echo "Error: the mail wasn't sent!";
}
header( "Location: http://www.gfunk-online.co.uk/confirmation.html" );

Posted: Thu Jun 08, 2006 4:23 am
by gkw
I tried using that and I get the message

$headers = 'From: '. $email. "\r\n"; $check = mail("bookings@gfunk-online.co.uk", "Feedback Form Results", $message, $headers); if($check == TRUE) { echo "Successfully sent! you can now check your email(".$to.")!"; }else{ echo "Error: the mail wasn't sent!"; } header( "Location: http://www.gfunk-online.co.uk/confirmation.html" );

I put the code in the <? ?> tags and I get

Successfully sent! you can now check your email()!
Warning: Cannot modify header information - headers already sent by (output started at e:\domains\g\gfunk-online.co.uk\user\htdocs\sendmail.php:6) in e:\domains\g\gfunk-online.co.uk\user\htdocs\sendmail.php on line 10

Posted: Thu Jun 08, 2006 10:54 am
by ok
First of all, put

Code: Select all

 and  if you post PHP code (it makes the reading easier)!!!
Secndly, make sure you have "short tags" enabled in php.ini (short tags = "<? ?>").
Thirdly, try replacing the last header ("Location...") with:
[syntax=php]echo '<html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.gfunk-online.co.uk/confirmation.html"></head></html>';[/syntax]

Posted: Thu Jun 08, 2006 12:19 pm
by gkw
Is this right?

Code: Select all

<?
$headers = 'From: '. $email. "\r\n"; 
$check = mail("bookings@gfunk-online.co.uk", "Feedback Form Results", 
$message, 
$headers); if($check == TRUE) { echo "Successfully sent! you can now check your email(".$to.")!"; 
}else{ echo "Error: the mail wasn't sent!"; } header( "echo '<html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.gfunk-online.co.uk/confirmation.html"></head></html>'; " ); 
?>

Posted: Thu Jun 08, 2006 12:48 pm
by Christopher
You can redirect either by specifying a Location in the HTTP headers:

Code: Select all

<?
header( 'Location: http://www.gfunk-online.co.uk/confirmation.html' ); 
?>
Or sending the page and using "Meta Refresh" to redirect:

Code: Select all

echo '<html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.gfunk-online.co.uk/confirmation.html"></head></html>';

Posted: Thu Jun 08, 2006 1:36 pm
by gkw
I can get the page to redirect using the first line you quoted but I still dont recieve any mail in my inbox. The second one I just get an error message.

Posted: Thu Jun 08, 2006 5:47 pm
by nathanr
try this:

Code: Select all

<? 
$from = 'From: '.$email."\r\n".'Reply-To: '.$email;

mail( "bookings@gfunk-online.co.uk", "Feedback Form Results", 
$message, $from); 
header( "Location: http://www.gfunk-online.co.uk/confirmation.html");
?>
:?:

Posted: Fri Jun 09, 2006 6:16 am
by gkw
That code works but I still dont recieve emails? My hosts do support cgi scripts etc.

Posted: Fri Jun 09, 2006 8:16 am
by nathanr
1: what happens when you send a normal email to bookings@gfunk-online.co.uk
2: have you checked any junk mail folders or filters you have
3: try sending it to a hotmail address or something instead as a test
4: contact your hosts to see if they support the php "mail" command

Posted: Sun Jun 11, 2006 1:27 pm
by gkw
1.When I send an email to bookings@gfunk-online.co.uk it forwards it to another account I use.
2.Yes ive checked my junk mail folders
3.Ive tried using my hotmail address but it still doesnt work.
4.In the help section on my hosts site (streamline.net) it has a tutorial on using PHP scripts which ive followed but cant get them to work. Ive also emailed them but they say they cant help with scripting code.

Posted: Mon Jun 12, 2006 7:30 am
by gkw
Anyone have any more ideas? Is there another easier way I can put a contact form on my site??

Posted: Mon Jun 12, 2006 8:17 am
by pawprint_net
is YOUR isp doing any sort of email filtering/blocking?

You may need to look at using -f as a parameter to mail() to force the from in the envelope. Or look at adding a SPF record to the mail server from which the server is sending. I have run into both these as being a source of problems for sending mail from a web server to several major ISPs - Yahoo being the most notable.

See the PHP docs on the -f (some hosting platforms may not allow it - unless you have access to your ini files)
See http://spf.pobox.com/ for more info on SPF (also can be tricky to add depending on your access to the server)

Posted: Mon Jun 12, 2006 8:29 am
by nathanr
you could try submitting the form to cgi formmail instead? or even better, ask your isp what they recommend you use / what others use

Posted: Mon Jun 12, 2006 5:49 pm
by gkw
I dont think they have any email filtering etc. My hosts wont help me with anything to do with designing my site, they only can help with hosting.

Looks like i'll have to give up on this contact form its getting to much and I dont understand why it isnt working.