PHP Contact Form Not Sending Email

Hello Everyone,
I'm trying to develop a website with a contact form.  I have received some help on this in the past from Ray (here) and Marco (here).  I think I Have everything set up correctly but I don't actually receive any email after clicking 'Submit'.  There is no error generated from the PHP mail function and the mail is not ending up in my Junk folder.  Nothing is happening at all.  I know this can be difficult to accomplish but I need to try.

I'm new to PHP and all things web development but I've been trying to learn as much as possible to try and figure this out.  Please let me know if I need to change something in the way I have this set up.  I think I may need send the Post array via an AJAX call in my JS instead of the way I'm doing it now.

All the files necessary to run my site via your local server are attached.  After loading the site from the index.php file click the Contact button in the Nav bar.  Fill out the form and click Submit.  Also, you'll probably want to change these two values for testing purposes.
Change To and From addresses for your testing purposes
Also, when you click Submit, the form will disappear.  You have to click on Contact again in order to see the 'Success' message.  I'm sure I'll need to ask another question to fix this, but one thing at a time :-).

Thanks in advance,
Kyle
MySite.zip
LVL 12
kgerbChief EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kgerbChief EngineerAuthor Commented:
I just received a test email to my outlook account from giuseppe so something is working :-).
Ray PaseurCommented:
You've probably picked one of the most difficult things to get right - email - and it's something I would leave out of the PHP learning process.  It often worms its way into early-learning PHP because it seems simple (everyone uses email, how hard can it be?) but there are a great many moving parts to email, including spam filters, that make it a maze of incompatibilities and dead ends.  If you really need email-related services, choose Constant Contact; don't try to write your own!

Let's try to deconstruct the problem.  

You need HTML forms and PHP action scripts to interact correctly.  There is a basic tutorial that teaches this.  You can follow this tutorial, build the contact form, and use var_dump() to print out the contents of your request variables.  Once you have verified that the data is coming through correctly from your browser request and into your server response, then it's time to go on to the next part of the application.
http://php.net/manual/en/tutorial.forms.php

Once you are sure that the plain old HTML+PHP forms are working, you can think about adding in an AJAX request.  You probably want to start by learning a bit of JavaScript, and implementing the AJAX request with jQuery.  This article can help you get started with jQuery, but don't rush yourself past the part about understanding JavaScript.  It's the world's most widely used programming language and as soon as you have linked any JavaScript into your web applications, you've deployed your programming on your client's browser.  That makes it important to understand what you're doing with JavaScript and get it right every time.
http://www.experts-exchange.com/articles/10712/The-Hello-World-Exercise-with-jQuery-and-PHP.html

Now that you've got the data going back and forth to the server in an AJAX application, you can start thinking about what you want to do with the data.  I would start by logging it into a file or database.  Logging is much more reliable than email.  You can look at your log files to verify your work.  With email, you may or may not get the signals you need in a timely way.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Marco GasiFreelancerCommented:
Yep, the mail from giuseppe was mine :-)
Your form works correctly: the email are sent with no exception. I can't reproduce the bug: the form remains visible. Don't remember if I've asked for this yet, but can you give a live link? So I can play with it to try to understand what happens. In my tests everything works as expected.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

kgerbChief EngineerAuthor Commented:
Marco,
I uploaded my new index.php file to the live server.  I just sent myself an email and it worked.  Can you please test it for me one more time.

Here's a link

At least it's something until I can get a more robust solution put together.  

Kyle
kgerbChief EngineerAuthor Commented:
Ray,
My plan is to move away from sending myself an email when the Submit button is clicked.  Instead I plan to log the data like you said.  What's your suggestion as to the best way to do this.  My first thought was to create a text file containing the form information each time someone submits something.  So essentially I would end up with a directory full of text files.  Then I thought I could also create an Access database and dump the data in there using ADO (I guess it would be ADO).  What is your suggestion?

Kyle
Marco GasiFreelancerCommented:
Done. Yes I see the form which goes away. Let me play a bit...
kgerbChief EngineerAuthor Commented:
Marco,
I just received 3 test messages from you.  The first was at 5:45pm and the last was at 5:49pm.  Is that how many you sent?

Kyle
Marco GasiFreelancerCommented:
3 emails yes.
About logging, if you want to use a text file just use file_put_contents() this way:

file_put_contents( 'LogFile.txt', $logString . "\n", FILE_APPEND );

Open in new window


But I usually log to a database table: it is just easier using standard db routines.
Marco GasiFreelancerCommented:
The form disappear because the default action of a submit input is to load the page specified in action property. Since action is empty, the form reload the actual page and this is what makes the form work and the email be sent. To avoid this, you should use Ajax to submit the form, but as I said it would be better if you delay Ajax until your confortable enough with php.
kgerbChief EngineerAuthor Commented:
Ray,
Thanks for the input and the article.  Excellent work.  I'm going to start working on logging the form info to a database.

Marco,
Thanks for the input as well.  I figured Submit was causing the page to reload.  

Thanks again to both of you.
Kyle
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.