Jump to content

Form Works


AnonymousX

Recommended Posts

I have a PHP form that sends messages to my email. Could somebody take a look at it, because it doesn't work all the time. Actually, it seems that it has only worked for me thus far.

<?php //Form Processing			if(isset($_POST['send'])) {				//Initialize error array				$errors = array();								//Check name field				if(empty($_POST['username'])) {					$errors[] = "Name field is required.";				}								//Check email field				if(empty($_POST['email'])) {					$errors[] = "E-mail field is required.";				}								//Check subject field				if(empty($_POST['subject'])) {					$errors[] = "Subject field is required.";				}								//Check message field				if(empty($_POST['message'])) {					$errors[] = "Message field is required.";				}								//If everything's okay				if(empty($errors)) {					//Send email					$body = "This message comes from your contact form on adhehsionarts.com\n\nName: {$_POST['username']}\nE-mail: {$_POST['email']}\nSubject: {$_POST['subject']}\nMessage: {$_POST['message']}";					mail('info@adhesionarts.com', $_POST['subject'], $body, 'From: '.$_POST['email']);										//Thank you message				header("Location: thankyou.php"); 													}			}			?>

Edit* I just received 2 more emails. That makes it 4/5 emails sent on Monday.

Link to comment
Share on other sites

So you're saying that the contact form on that server only works half the time? For whatever reason I thought you were trying this on different servers. There might be restrictions on the hosting account where they are only allowed to send a certain amount of messages every hour. You can use an if statement with the mail function to check if it fails and show an error message if it does. Unfortunately, PHP isn't aware of every step of the mailing process, all PHP is responsible for is giving the mail message to the mail transfer agent. The MTA is what is ultimately responsible for sending off the mail, and if it fails doing that it doesn't have a way to send a message back to PHP telling it that the mail didn't get sent. So, PHP will return true for the mail function if the mail was successfully sent to the MTA. If the mails always go to the MTA but only some of them get sent, you might need to check with your host and see if there's anything funky going on with the transfer agent or mail server, and make sure you keep an eye on spam folders to see if the message got flagged as spam.if (!mail(...))

Link to comment
Share on other sites

I've had a discussion with the support staff for my web space, and have confirmed that no filters are in effect to limit the number of emails I receive. I did however receive 2/5 emails that were sent on Monday afternoon this (Wednesday) morning. They suggested that I check my form again, to make sure that it works alright. I'll continue to watch my inbox for the remaining messages, but what would be causing this delay?

Link to comment
Share on other sites

This is a complete guess but...What email provider are you using? Like gmail or something? If your using one of those then check your settings on those. Also check the steps that your email form takes before it sends to you. Try limiting what you have on there. Also compare why some emails send and why some don't. Try sending a few emails to yourself with different formats and see which ones consistently go through. Perhaps then you can identify the problem..?

Link to comment
Share on other sites

justsomeguy how do u know so much about MYSQL, PHP, HTML, JAVA, JS, + whatever else???
Just experience using them, and in college the best thing I learned was how to do research. Many of the answers I give I just looked up.
I've had a discussion with the support staff for my web space, and have confirmed that no filters are in effect to limit the number of emails I receive. I did however receive 2/5 emails that were sent on Monday afternoon this (Wednesday) morning. They suggested that I check my form again, to make sure that it works alright. I'll continue to watch my inbox for the remaining messages, but what would be causing this delay?
That's sort of interesting, I wonder how mail servers are doing lately in general. I have received virtually no spam the last couple days, and someone else I sent an email to received it after a delay. Normally that shouldn't happen. I wonder if there is something else going on with the internet in general that is causing this. It might depend on the network the mails happen to be going through, last week the federal government accidentally deleted the .ca.gov domain, if the mails are travelling through one of those servers somewhere along the way there might be some confusion with the DNS records or something like that. I also just saw a stat that said that 95% of all internet email traffic is now spam. I guess it might be possible that the system is just congested and things are taking a while, but that doesn't sound very likely. But one thing I can say for sure is that the code is fine. The only thing I can see is that you don't display the error messages, so you wouldn't know if the mail doesn't get sent (unless you do that elsewhere). Other then that it looks fine though.
Link to comment
Share on other sites

Going along with what JustSomeGuy said, I think something is wrong with the email servers. I have heard that rumor too about ca.gov. It's quite possible that the internet email process is taking a hit right now. Try going to a library and doing the form. Try if that works on several computers and see when it is fixed. When I first looked at the code I thought it looked fine, so just give it time. Probably a server problem

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...