PHP Form Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

PHP Form Help

Post 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
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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" );
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post 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
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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]
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post 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>'; " ); 
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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>';
(#10850)
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post 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.
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post 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");
?>
:?:
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post by gkw »

That code works but I still dont recieve emails? My hosts do support cgi scripts etc.
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post 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
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post 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.
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post by gkw »

Anyone have any more ideas? Is there another easier way I can put a contact form on my site??
User avatar
pawprint_net
Forum Newbie
Posts: 9
Joined: Sat Jun 10, 2006 11:35 pm
Location: Sechelt BC Canada
Contact:

Post 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)
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post 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
gkw
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 3:54 am

Post 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.
Post Reply