If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

PHP Mail form

Hi, I am new to using PHP (in fact its my very first time) and I have to finish a contact form for class. We have to make a form that includes name, email, birthday, and a message box. When it submits, the information has to be sent to both me and the user, and the page displays a thank you message.

I am wondering how to get the code to also email to the recipient, myself, and display the thank you message at the end. Every time I hit submit I get a 404 error. What am I doing wrong and how can I fix this?

since you have the form submitting to its self. meaning the same page that the php is on remove the contact.php in action and just leave it blank like this action=""> start with that see if that helps

Ok, that got rid of the 404 error. So then I tested out the form several times but it only sent one notification to me. Sadly it just sent the notification, subject, and time, but not any of the information I need such as birthdate, sender's name and sender's email address.

ok good. that means we are narrowing down the problems. so we need to look at the code again now. I like to keep my php separate from my forms personally but. let me add it to my text editor and see if i can make some changes.

the only thing you could change is the variable called $to change it to the email address this form is supposed to send to. as far as for the 2nd email it will just send to what ever someone types in to the form.

I appreciate your feed back.
But I am not the one asking a question on this thread. I am providing help to a person who had a question that has been answered for days now. as for putting php and html in the same file it should be avoided in most cases due to security risks. a few examples being when connecting to a database, dealing with a page controlled by a session, or when your passing personal information that should be secure through the server. At the end of the day to each his own and I think its important to see many different examples on how to accomplish any task. The more examples people are given when asking a question on a forum the better, because it allows them to have a better idea of what they are doing. its hard to learn for some people because there are so many ways to accomplish the same task.

I make a point to answer as many questions as I can because I to have questions and i appreciate when people answer my questions promptly.

I personally like my files to be organized easy to read and secure. So I make a point to avoid mixing php and html unless there is a reason for it.

I think for the sake of being helpful to the person who started this thread, it would be more productive to give them an example of the way you would accomplish
this task instead of telling me you don't like the way I structure my code. unfortunately all that does is leave confusion for someone who comes along looking for
an answer on this thread and the last post they see is your post telling me what you feel I did wrong with out giving an example of how you feel the correct way of doing this was.

I am sure you have your own style as I have mine, and I am sure it will be helpful for people to see because in some cases some people might find my code was easier for them to understand
and in other cases people may relate better to the way you do things.

I realize this is an email form but just recently I was working on a form with a person who wanted to keep the email address private. That means it was necessary to keep the php in a separate file. So i try to keep good habits instead of picking and choosing when to make a simple script less secure just for the sake of not feeling like its necessary to be more secure on this one.

Hope to see an example from you so we can add some more content to the site. The More examples more questions get answered.

Also if you are seeing something in my script that is wrong please elaborate. I am here to learn and appreciate any chance to learn something new.