trouble with php mail script

keeps displaying php file instead of sending mail

Page 1 of 1

8 Replies - 1564 Views - Last Post: 25 May 2009 - 10:00 PM Rate Topic: -----

#1 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

trouble with php mail script

Posted 25 May 2009 - 09:30 PM

Hello everyone,

So this here is my first ever PHP script and I seem to be having a few issues with it. What's happening is when I press the submit button it displays the sendMail.php script in the browser as opposed to actually sending me mail. I do not currently have the site on the web, as it's still in development stages, so that may have something to do with it. Anyways I'll post my code(not very much of it) and see what you guys think....Cheers

html code....
				<form method="post" action="sendMail.php">
					  Email: <input name="email" type="text" size="30"/><br />
					  Subject: <input name="subject" type="text" size="30"/><br />
					  Message:<br />
					  <textarea name="message" rows="15" cols="80">
					  </textarea><br />
 				 	<input type="submit" />
				</form>


And PHP...
<?php
  $email = $_REQUEST['email'];
  $message = $_REQUEST['message'];
  $subject = $_REQUEST['subject'];

  if (!isset($_REQUEST['email'])) 
  {
	header( "Location: feedback.html" );
  }
  elseif (empty($email) || empty($message)) 
  {
	header( "Location: error.html" );
  }
  else 
  {
	mail( "[email protected]", "Blog Comment",
	  Subject: $subject\n\n,$message, "From: $email" );
	header( "Location: thankyou.html" );
  }
?>


Is This A Good Question/Topic? 0
  • +

Replies To: trouble with php mail script

#2 Martyr2   User is online

  • Programming Theoretician
  • member icon

Reputation: 5226
  • View blog
  • Posts: 14,006
  • Joined: 18-April 07

Re: trouble with php mail script

Posted 25 May 2009 - 09:39 PM

Do you have a web server running on your computer and PHP installed on it? You have to have both of these pieces of software actually running. What is happening is that when you send the request to the PHP file, the computer says "I have no clue what a PHP file is, so I will give you its contents" and then spits the text of the script out.

Now if you have a web server installed and running with PHP, it will see the .PHP file type and know that it is to pass the file to the PHP interpreter and translate the code.

Are you able to run any other .PHP files normally? Have you done a simple hello world application?

:)
Was This Post Helpful? 0
  • +
  • -

#3 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: trouble with php mail script

Posted 25 May 2009 - 09:41 PM

Check Here
Was This Post Helpful? 0
  • +
  • -

#4 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: trouble with php mail script

Posted 25 May 2009 - 09:42 PM

View PostMartyr2, on 25 May, 2009 - 08:39 PM, said:

Do you have a web server running on your computer and PHP installed on it? You have to have both of these pieces of software actually running. What is happening is that when you send the request to the PHP file, the computer says "I have no clue what a PHP file is, so I will give you its contents" and then spits the text of the script out.

Now if you have a web server installed and running with PHP, it will see the .PHP file type and know that it is to pass the file to the PHP interpreter and translate the code.

Are you able to run any other .PHP files normally? Have you done a simple hello world application?

:)



I do not in fact have a Web Server running here, I was going to be using a hosting service as I really don't have a comp I can use to run Apache on at the moment. Second, I haven't even really tried doing a hello world app either. So in this case is it possible to test out PHP script before it goes live? or does that all have to be done when It's actually running on the web server?
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2   User is online

  • Programming Theoretician
  • member icon

Reputation: 5226
  • View blog
  • Posts: 14,006
  • Joined: 18-April 07

Re: trouble with php mail script

Posted 25 May 2009 - 09:49 PM

Well you have to actually test it on a machine that has a web server with PHP installed and running. If you have a host for this, fine. Just upload it to your host with special hidden directory somewhere and then navigate to it.

I always start by creating a special folder somewhere I can put my test files while developing. That way I can write some code, upload it to my host, navigate to it through the web and see the result. Tip: Leave the browser window open after that and then you can just hit refresh after each change (and re-upload).

:)
Was This Post Helpful? 1
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6643
  • View blog
  • Posts: 30,932
  • Joined: 10-May 07

Re: trouble with php mail script

Posted 25 May 2009 - 09:49 PM

View Postmarkhazlett9, on 25 May, 2009 - 10:42 PM, said:

I do not in fact have a Web Server running here,

You must have a php engine running to compile & run the code.
Was This Post Helpful? 0
  • +
  • -

#7 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: trouble with php mail script

Posted 25 May 2009 - 09:50 PM

View PostMartyr2, on 25 May, 2009 - 08:49 PM, said:

Well you have to actually test it on a machine that has a web server with PHP installed and running. If you have a host for this, fine. Just upload it to your host with special hidden directory somewhere and then navigate to it.

I always start by creating a special folder somewhere I can put my test files while developing. That way I can write some code, upload it to my host, navigate to it through the web and see the result. Tip: Leave the browser window open after that and then you can just hit refresh after each change (and re-upload).

:)



perfect i'll give that a try as soon as I get my host up! Cheers Martyr! Helpful as usual!

Just another quick question on this... Is PHP the best way to do this? Or is it better to do this with another language that doesn't require a server up.

Cheers

This post has been edited by markhazlett9: 25 May 2009 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6643
  • View blog
  • Posts: 30,932
  • Joined: 10-May 07

Re: trouble with php mail script

Posted 25 May 2009 - 09:58 PM

View Postmarkhazlett9, on 25 May, 2009 - 10:50 PM, said:

Just another quick question on this... Is PHP the best way to do this? Or is it better to do this with another language that doesn't require a server up.

In order for your application to be accessible via the web, it must run on a webserver.

Otherwise, you'll need to setup a POP email server. The webserver is probably going to be the most ideal for what you are doing.
Was This Post Helpful? 1
  • +
  • -

#9 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: trouble with php mail script

Posted 25 May 2009 - 10:00 PM

View Postno2pencil, on 25 May, 2009 - 08:58 PM, said:

View Postmarkhazlett9, on 25 May, 2009 - 10:50 PM, said:

Just another quick question on this... Is PHP the best way to do this? Or is it better to do this with another language that doesn't require a server up.

In order for your application to be accessible via the web, it must run on a webserver.

Otherwise, you'll need to setup a POP email server. The webserver is probably going to be the most ideal for what you are doing.



Perfect! Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1