LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-09-2010, 07:00 AM   #1
Chris1989
LQ Newbie
 
Registered: Oct 2009
Distribution: Fedora 11 + CentOS 5.1
Posts: 17

Rep: Reputation: 3
Basic PHP Mail function help


Hi guys my php code is this

PHP Code:
<?php
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '') {
    
$to "my@email.com";
    
$subject "Contact Form Enquiry";
    
$message $_REQUEST["message"];
    
$from $_REQUEST["email"];
    
mail($to,$subject,$message,$from);
    
header('Location:/thanks.php');}
else{
header('Location:/error.php');
exit();
}
?>
And my html is this...

Code:
	<form id="form" action="contactscript.php" method="post">
               <fieldset id="field">
                  <legend id="leg">Contact Form</legend>

                  <span class="formtext"><label for="fname">First Name:</label></span>	<input class="input" id="first" name="first" type="text" size="30" /><br /><br />
                  <span class="formtext"><label for="sname">Surname:</label></span>		<input class="input" id="surname" name="surname" type="text" size="30" /><br /><br />
                  <span class="formtext"><label for="email">Email:</label></span>		<input class="input" id="email" name="email" type="text" size="30" /><br /><br />
                  <span class="formtext"><label for="contac">Contact Number:</label></span>		<input class="input" id="contact" name="contact" type="text" size="30" /><br /><br />
                  <span class="formtext"><label for="message">Message:</label></span> 	<textarea id="textarea" name="message" class="input" rows="10" cols="30" >Please Type Your Message Here</textarea><br /><br />
                  										<input id="submit" class="input" type="submit" value="Send!"  />
                  														
               </fieldset>
            </form>
Now if my site is hosted locale (127.0.0.1) the script runs (apart from sending the email) and redirects to the correct pages stated in the header() function. However if I host the site on the internet when I click on the submit button instead of executing the script it pops open with a dialogue box to state whether I wasn't to download/open the script like when you click on a file to download...

Anyone know why this is happening??

Any help is majorly appreciated!
 
Old 09-09-2010, 07:18 AM   #2
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
You dont have php enabled/installed on your server.
 
Old 09-09-2010, 07:51 AM   #3
Chris1989
LQ Newbie
 
Registered: Oct 2009
Distribution: Fedora 11 + CentOS 5.1
Posts: 17

Original Poster
Rep: Reputation: 3
PHP is installed as my site is/was created using PHP includes and the browser processes them fine.
 
Old 09-09-2010, 08:07 AM   #4
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Something isn't right on your server. My first thought was that php
isn't installed or configured correctly, but I'm starting to think
that your php script is running and, for some reason, is having a
problem presenting the /thanks.php or the /error.php page.

I'd suggest that you download the file and look at its contents.
Also load the /thanks.php and /error.php pages, just to make sure
they display properly. Note that the system may expect "<?php " and
these pages might simply have "<? ".
 
Old 09-09-2010, 08:56 AM   #5
Chris1989
LQ Newbie
 
Registered: Oct 2009
Distribution: Fedora 11 + CentOS 5.1
Posts: 17

Original Poster
Rep: Reputation: 3
when i type the address ending "/thanks.php" it opens the dialogue box to download the file like when I click on the submit button.

All my php is started with "<?php" so its not that.

Its really bugging me, have no idea why its doing it.

Thanks.
 
Old 09-09-2010, 09:06 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
>From the PHP manual:

Quote:
HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
Maybe that's your problem?
 
1 members found this post helpful.
Old 09-09-2010, 09:49 AM   #7
Chris1989
LQ Newbie
 
Registered: Oct 2009
Distribution: Fedora 11 + CentOS 5.1
Posts: 17

Original Poster
Rep: Reputation: 3
Ive got it as the absolute file path and still doing the same.
 
0 members found this post helpful.
Old 09-09-2010, 07:23 PM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Is the email sent?
Do you have any error messages in you apache log?
Is anything written out before the header (check for blank lines or spaces)?
 
Old 09-13-2010, 03:41 AM   #9
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
Code:
header('Location:/thanks.php');}
should be:

Code:
header("Location: /thanks.php");}
Dont mix up ' with "

Oh, and:

Quote:
Originally Posted by php.net
2. Then there MUST be colon and space, like

good: header("Content-Type: text/plain");

wrong: header("Content-Type:text/plain");
So your going to HAVE to use the full URI.

Last edited by djsmiley2k; 09-13-2010 at 03:49 AM.
 
Old 09-13-2010, 04:00 AM   #10
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by djsmiley2k View Post
Dont mix up ' with "
Wouldn't make any difference. The double quote will allow for string substitution but since there isn't any going on in this scenario both single and double quotes will work the same.
 
Old 09-13-2010, 04:22 AM   #11
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
Quote:
Originally Posted by graemef View Post
Wouldn't make any difference. The double quote will allow for string substitution but since there isn't any going on in this scenario both single and double quotes will work the same.
It may do if hes updated the url to use $HOST_ .
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Mail function phantom_cyph Programming 6 05-15-2008 11:45 PM
mail-function php sharp81 Linux - Software 3 02-17-2006 09:45 AM
HELP !!! php mail function akamaru607 Programming 22 08-26-2005 02:44 PM
PHP - mail function saravanan1979 Programming 2 08-06-2003 01:46 AM
Using the PHP mail() Function !?!? Hdata Programming 0 06-22-2003 06:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration