Jump to content


Photo

Contact Form Not Sending Emails

contact form

  • Please log in to reply
11 replies to this topic

#1 flatrabbit

flatrabbit

    Newbie

  • New Members
  • Pip
  • 8 posts

Posted 30 December 2012 - 06:21 PM

I have a simple php contact form:
http://brand32.com/c...rk/contact.html

Upon clicking "Send" the message displays "Your message has been sent successfully!" but no email is received. I've changed the email in the code multiple times, but the same result (or lack thereof).

Here is the php code:

<?php

$receiverMail

= "seanmcpeak@comcast.net"; /* Your email */


$name


= ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));

$email


= ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));

$website

= ltrim(rtrim(strip_tags(stripslashes($_POST['website']))));

$msg


= ltrim(rtrim(strip_tags($_POST['msg'])));

$subject = $name ." - ".$website;

$ip


= getenv("REMOTE_ADDR");

$msgformat

= "From: $name ($ip)\nEmail: $email\n\n$msg"; /* MSG format */



// VALIDATION


if(empty($name) || empty($email) || empty($website) || empty($msg)) {



echo "<div id='status' class='error'>The email was not sent. Please fill all the required fields</div>";

}

elseif(!
ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {



echo "<div id='status' class='error'>The email was not sent. The email address is invalid</div>";

}

else {




mail($receiverMail, $subject, $msgformat, "From: $name <$email>");



echo "<div id='status' class='ok'>Your message has been sent successfully!</div"; }

?>


Thanks in advance.

#2 scootstah

scootstah

    Advanced Member

  • Gurus
  • 2,889 posts
  • LocationUSA

Posted 30 December 2012 - 06:25 PM

Wow, that is some very outdated code.

Do you have a working mail server installed?
while(!$succeed = try());

#3 flatrabbit

flatrabbit

    Newbie

  • New Members
  • Pip
  • 8 posts

Posted 30 December 2012 - 06:27 PM

I don't understand. It came with a template. Its on a linux hosting account with GoDaddy running php 5.2

#4 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 881 posts
  • LocationLondon, UK

Posted 30 December 2012 - 06:29 PM

That's quite an old script you've found somewhere. The ereg() function is deprecated as of PHP 5.3.0 and I'd like to think the version your using is more current, perhaps not though. Instead of sanitising the website (which is wrong in its current state) and email why not validate them using the preg_match function and error if false; its normally better to define what is allowed than remove everything that's not or test for everything that's not.

I'd imagine the ereg is causing problems so get it changed to preg_match.

Edited by CPD, 30 December 2012 - 06:30 PM.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#5 flatrabbit

flatrabbit

    Newbie

  • New Members
  • Pip
  • 8 posts

Posted 30 December 2012 - 06:30 PM

Thanks for your help guys, but you're way over my head. :(

#6 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 881 posts
  • LocationLondon, UK

Posted 30 December 2012 - 06:32 PM

Thanks for your help guys, but you're way over my head. :(


Soo....
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#7 scootstah

scootstah

    Advanced Member

  • Gurus
  • 2,889 posts
  • LocationUSA

Posted 30 December 2012 - 06:35 PM

Before we go any further, let's make sure this is a code problem and not a server problem. Create a new .php file and put only the following in to it:
<?php

if (mail("seanmcpeak@comcast.net", "This is a test", "This is a test")) {
	echo 'success';
} else {
	echo 'fail';
}

Make sure the "seanmcpeak@comcast.net" is where you want the test to be sent.

Run the script on your GoDaddy server. If you get "success", make sure the mail is delivered. If it was, then we know it is a problem in your code above. If not, then something on the server is not configured properly.
while(!$succeed = try());

#8 flatrabbit

flatrabbit

    Newbie

  • New Members
  • Pip
  • 8 posts

Posted 30 December 2012 - 07:04 PM

Before we go any further, let's make sure this is a code problem and not a server problem. Create a new .php file and put only the following in to it:

<?php

if (mail("seanmcpeak@comcast.net", "This is a test", "This is a test")) {
	echo 'success';
} else {
	echo 'fail';
}

Make sure the "seanmcpeak@comcast.net" is where you want the test to be sent.

Run the script on your GoDaddy server. If you get "success", make sure the mail is delivered. If it was, then we know it is a problem in your code above. If not, then something on the server is not configured properly.


No email and the page displayed 'fail'

#9 flatrabbit

flatrabbit

    Newbie

  • New Members
  • Pip
  • 8 posts

Posted 30 December 2012 - 07:38 PM

Soo....

I was referring to ereg and preg_match

#10 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 30 December 2012 - 07:41 PM

Then your host does not have a working MTA (Mail Transfer Agent) you can use, and thus you're unable to send e-mails via the mail () function.
As for the functions listed above that you didn't understand, the PHP manual is a great resource for explaining them.

I recommend, first and foremost, to read up on the basics of PHP. Having the basic knowledge in place will allow you to better understand what you're working on, and thus have a better chance at making something work.
Once you've done that, I strongly recommend that you dismiss the script above, as it's seriously outdated and insecure. Instead you should take a look at PHPmailer, and use it for your contact script.

Lastly, if you can't get that to work, then you need to change hosts.

PS: Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read.
Keeping it simple.

#11 flatrabbit

flatrabbit

    Newbie

  • New Members
  • Pip
  • 8 posts

Posted 30 December 2012 - 07:56 PM

Then your host does not have a working MTA (Mail Transfer Agent) you can use, and thus you're unable to send e-mails via the mail () function.
As for the functions listed above that you didn't understand, the PHP manual is a great resource for explaining them.

I recommend, first and foremost, to read up on the basics of PHP. Having the basic knowledge in place will allow you to better understand what you're working on, and thus have a better chance at making something work.
Once you've done that, I strongly recommend that you dismiss the script above, as it's seriously outdated and insecure. Instead you should take a look at PHPmailer, and use it for your contact script.

Lastly, if you can't get that to work, then you need to change hosts.

PS: Please use the tags around your code, as it helps make both your post and your code a lot easier to read.


Thanks man. I'll get to reading and check out PHPmailer. Great resources. Cheers.

#12 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 30 December 2012 - 08:23 PM

Before you go run off and do that, you might want to check GoDaddy's FAQs. I've never had a problem sending mail from one of their hosting servers.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com