7 Replies - 6671 Views - Last Post: 12 August 2011 - 09:19 PM Rate Topic: -----

#1 wgrayson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 18-May 09

of PhP, GoDaddy and using databases and default email form!

Posted 10 August 2011 - 01:52 PM

After a week and help from this forum and tne internet, I created a simple form that captured data to a mySql database.
I got it to work on a localhost, and then uploaded it to run-of-the-mill goDaddy windows webserver. (I chose Windows in the event I ever learned aspx and I was told that php script would run fine). The code works fine and captures data to a mysQl database I set up on my webserver.

Now comes the hard part. I also want to email the form data as well as capture it to a database. I learned how to use the php mail() function to do it on my local server. I needed to configure my php.ini file to do so, but it works locally. GoDaddy, unfortunately, has a required form script that must use the "action = [godaddy-required file] method = POST" in the form field. Which bites because I'm using to action command to initiate the file that runs the php / mysql code, validation file, etc. No help from godaddy on this one other than "it's possible but you have to write a custom script."

By the way, on my localhost, I capture to a database and email by using INCLUDE to place a file with the mail() function at the end of all my my database code --- I've set the Post variables as global. It works. I tried to INCLUDE the GoDaddy file the same way, but it doesn't work.

What's my next step? Thanks,


W!

Is This A Good Question/Topic? 0
  • +

Replies To: of PhP, GoDaddy and using databases and default email form!

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 10 August 2011 - 11:47 PM

Great, DIC went down and lost my post...

Anyway I said something along the lines of this:
GoDaddy won't require you to use a script and if they do you should find a new host.

mail() should work the same, however you need to define both an SMTP Server and From address (mostly) to be able to send via a Windows Server.

What error do you get when you attempt to use mail() at the moment? They're normally extremely self-explanitory and can be fixed in around 10 seconds.
Was This Post Helpful? 0
  • +
  • -

#3 wgrayson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 18-May 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 11 August 2011 - 01:20 PM

Rudivisser: Thanks for responding. This is actually what happens: There's no error message when I use the mail() function. I've even built in an echo "success" and echo "failure" if the email component doesn't work. What happens is this:

When the form data is entered, NO message appears for the mail function. No "success." No "failure." I may get an email message in my inbox, but it does not contain the actual form data. It shows the actually field headings: "First Name", "Last Name," "email," etc., but none of the post data variable data ($lastName, $company, etc) passes through to the email.

<?php
$from_name = "WendellTesting";
$from_email = "wendell@email.com";
$headers = "From: $from_name <$from_email>";
$body = "The following RSVP was received on $rsvpDate\r\n
         First Name: $firstName\r\n 
		 Last Name:  $lastName\r\n
		 Company: $company\r\n
		 Number Attending: $numberAttending\r\n
		 Email:$email\r\n 
		 Phone: $phone\r\n
		 Source: $source\r\n";
$subject = "RSVP Form response";
$to = "wendell@email.com";

if (mail($to, $subject, $body, $headers)) {
  echo "success!";
} else {
  echo "fail…";
}
?>



As I may have mentioned, this script is in a standalone file named "sendRSVP.php" which "included" at the end of the Results / Processor file that runs the mySql script to insert records into the database.

By the way, I declared all the $_POST variables as globals in the Results/Processor file, so I assume they would pass through to the mail function. At least it works on my localhost that way. . . . .
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 11 August 2011 - 01:26 PM

View Postwgrayson, on 11 August 2011 - 09:20 PM, said:

<?php
$body = "The following RSVP was received on $rsvpDate\r\n
         First Name: $firstName\r\n 
		 Last Name:  $lastName\r\n
		 Company: $company\r\n
		 Number Attending: $numberAttending\r\n
		 Email:$email\r\n 
		 Phone: $phone\r\n
		 Source: $source\r\n";


So from what you've said, emails are working fine as you're getting the above without the variables, so have you checked that the variables are actually set?

Debug this by var_dumping them one by one. You should use var_dump as it will tell you the type, including NULL if they're undefined. You say it's a standalone script but it's included, so it's not standalone? I'm confused.

Also, have you tried doing a var_dump($_POST) to see if everything's getting posted through okay aswell?

BTW, to get a white screen (ie. no success/failure), some form of error must've been thrown so you can do ini_set('display_errors', 1); to take a look at them.
Was This Post Helpful? 2
  • +
  • -

#5 wgrayson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 18-May 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 12 August 2011 - 06:34 AM

Thanks again. By "standalone" I meant the mail function was in a separate file that was included, as opposed to being part of the same file that runs the mySQL stuff to insert the records into a database. You know, I can monkey around with the mail function code and not disturb the other code that's working.

I did have a thought as well that perhaps there's something about that goDaddy server setup that's interfering with passing the variables ---- the variables pass fine on my local host AND on my work web server where I've tested it. I am going to test the variables per your suggestion this weekend to see what happens. I will keep you posted.
Was This Post Helpful? 0
  • +
  • -

#6 wgrayson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 18-May 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 12 August 2011 - 03:37 PM

Attention Rudivisser:

Success. Thank you. I didn't run the var_dump to debugt, I just added the $_POST variables to the code you see below and it worked.

It threw me off because on the localhost test, all my code recognized the $_POST variables ($firstName, $lastName, $email, etc)I declared as a Global variable, so I didn't need to repeat it for every separate function or page. However, that didn't occur on goDaddy's server.

Hmmmmm. But I'll chalk this up as problem solved. I'll move on to more advanced coding like, how to export all that mySQL data to a .csv file!

View PostRudiVisser, on 11 August 2011 - 02:26 PM, said:

View Postwgrayson, on 11 August 2011 - 09:20 PM, said:

<?php
$body = "The following RSVP was received on $rsvpDate\r\n
         First Name: $firstName\r\n 
		 Last Name:  $lastName\r\n
		 Company: $company\r\n
		 Number Attending: $numberAttending\r\n
		 Email:$email\r\n 
		 Phone: $phone\r\n
		 Source: $source\r\n";


So from what you've said, emails are working fine as you're getting the above without the variables, so have you checked that the variables are actually set?

Debug this by var_dumping them one by one. You should use var_dump as it will tell you the type, including NULL if they're undefined. You say it's a standalone script but it's included, so it's not standalone? I'm confused.

Also, have you tried doing a var_dump($_POST) to see if everything's getting posted through okay aswell?

BTW, to get a white screen (ie. no success/failure), some form of error must've been thrown so you can do ini_set('display_errors', 1); to take a look at them.

Was This Post Helpful? 0
  • +
  • -

#7 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 12 August 2011 - 03:41 PM

View Postwgrayson, on 12 August 2011 - 11:37 PM, said:

It threw me off because on the localhost test, all my code recognized the $_POST variables ($firstName, $lastName, $email, etc)I declared as a Global variable, so I didn't need to repeat it for every separate function or page. However, that didn't occur on goDaddy's server.

Hmmm it sounds like you have register_globals on locally which is bad!

You should turn this off (in your php.ini) as soon as possible so you can start writing proper code from the start ASAP :)

Also, if you're new to development, turn your error reporting to E_ALL | E_STRICT, so you're getting all of the possible errors PHP could ever give to you. This will possibly "throw you in at the deep end" so to speak, but you'll be a better coder for it!

Glad you got it sorted :rockon:
Was This Post Helpful? 1
  • +
  • -

#8 wgrayson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 18-May 09

Re: of PhP, GoDaddy and using databases and default email form!

Posted 12 August 2011 - 09:19 PM

View PostRudiVisser, on 12 August 2011 - 04:41 PM, said:

View Postwgrayson, on 12 August 2011 - 11:37 PM, said:

It threw me off because on the localhost test, all my code recognized the $_POST variables ($firstName, $lastName, $email, etc)I declared as a Global variable, so I didn't need to repeat it for every separate function or page. However, that didn't occur on goDaddy's server.

Hmmm it sounds like you have register_globals on locally which is bad!

You should turn this off (in your php.ini) as soon as possible so you can start writing proper code from the start ASAP :)

Also, if you're new to development, turn your error reporting to E_ALL | E_STRICT, so you're getting all of the possible errors PHP could ever give to you. This will possibly "throw you in at the deep end" so to speak, but you'll be a better coder for it!

Glad you got it sorted :rockon:


Will do. Good tips. I'll start poking around my local server's php.ini file now. And as much as I hate to do it, I'll also enable strict error reporting. Now, I think I get it. Perhaps the XAMPP version I'm using (1.7.3) needs a little php.ini tweaking.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1