Log in

View Full Version : Email not sending



DS928
09-20-2013, 05:07 PM
I have a website with a contact form. The PHP code is at the top of the page. It is being called from the Form action. I am not getting any error messages. It seems to be working except that the emails aren't being sent. The page is...

http://www.schuremediagroup.com/#!/page_Contact

you can try it, and you'll see that it seems to be working, but alas I am not receiving any emails.



<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "ds@schuremediagroup.com";
$email_subject = "SMG Contact";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die(); }
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.'); }
$subject = $_POST['subject'];
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />'; }
$string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) {
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />'; }
if(strlen($error_message) > 0) {
died($error_message); }
$email_message = "Information.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string); }
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n".
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<div class="boxer" "visibility:hidden">
<div class="close_boxer" align="right">X</div>
<div align="center">
Request Sent. Thank you!
</div>
</div>
<?php
}
?>



Any help is appreciated. Thank you.

Beverleyh
09-20-2013, 05:21 PM
I haven't tested or looked too closely at your code as I'm on iPhone at the mo, but for starters, are you 100% sure that you have mailing enabled on your web host account? I ask because its more often than not disabled on free accounts (you don't say if that's the case but I just thought I'd throw it in there) and that sometime stumps folks before they even get started.

DS928
09-20-2013, 05:38 PM
I haven't tested or looked too closely at your code as I'm on iPhone at the mo, but for starters, are you 100% sure that you have mailing enabled on your web host account? I ask because its more often than not disabled on free accounts (you don't say if that's the case but I just thought I'd throw it in there) and that sometime stumps folks before they even get started.
Thank you. The email account is not a free account. It is with GoDaddy. When I had the php file on a seperate page it worked. But then I moved it to the same page as the form and now it doesn't. I moved it so that I would get the popup div that the email was sent.

traq
09-20-2013, 07:05 PM
Do you have error reporting enabled?
Are you getting any error messages?

Also,

@mail($email_to, $email_subject, $email_message, $headers);

The error suppression operator ( @ ) allows you to implement your own error handling, but, in this case, it is simply being used to ignore errors. This is never A Good Thing.

For example, your call to mail() is failing, but you will never know why because the error is ignored.

Instead, try something like:

# @mail($email_to, $email_subject, $email_message, $headers);

if( mail($email_to, $email_subject, $email_message, $headers) ){
/* success! show a thank-you message. */
}
else{
/* failure. show an error message. */
}

DS928
09-20-2013, 07:45 PM
Thank you. I did as you suggested and I am receiving no error messages. I think its fair to point out that I tried several email forms and they all said that the email was sent. However; I did not receive anything. I checked with GoDaddy and they said all is well at their end. Preplexing.

DS928
09-20-2013, 08:02 PM
Eureka! Something showed up.

[Fri Sep 20 12:56:10 2013] [error] [client 67.82.108.194] File does not exist: /var/chroot/home/content/d/s/t/dstr3/html/SMG/favicon.ico
[Fri Sep 20 12:56:10 2013] [error] [client 67.82.108.194] File does not exist: /var/chroot/home/content/d/s/t/dstr3/html/SMG/missing.html

traq
09-20-2013, 09:18 PM
Eureka! Something showed up.

[Fri Sep 20 12:56:10 2013] [error] [client 67.82.108.194] File does not exist: /var/chroot/home/content/d/s/t/dstr3/html/SMG/favicon.ico
[Fri Sep 20 12:56:10 2013] [error] [client 67.82.108.194] File does not exist: /var/chroot/home/content/d/s/t/dstr3/html/SMG/missing.html

those seem unrelated to your script.


Did you determine if the mail function is returning true or false (i.e., did you see your "success" message or your "error" message)?

Did you make sure PHP's error reporting is enabled?

DS928
09-21-2013, 12:27 AM
those seem unrelated to your script.


Did you determine if the mail function is returning true or false (i.e., did you see your "success" message or your "error" message)?

Did you make sure PHP's error reporting is enabled?

After several calls to GoDaddy they finally aditted that where my email resides on the server the que is jammed and I just have to wait. Thank you for your help.

DS928
09-21-2013, 12:50 AM
How do you close this thread?

djr33
09-21-2013, 01:36 AM
Is it working now? Is that the only issue? That's very strange. I wouldn't be surprised by a 5 minute delay, or maybe even a one time delay of an hour or two, but to have it down for long enough to have this whole conversation... GoDaddy did something very, very wrong.* And they're usually reliable. Keep an eye on this. One the other hand, their tech support, in my experience, is far from the best. So if you still have issues, don't hesitate to talk to a manager, get a second opinion, etc.
(*Alternatively, it is, I suppose, possible that someone was abusing the email services on that server. Maybe that shut it down for everyone.)


As for closing the thread, we don't usually do that (unless there's a specific reason to). Instead, we would ask that you go to your first post, click edit (and then enter the "advanced" mode, rather than then "quick" mode). Then you can select "Resolved" from a dropdown menu. We'll know the problem is resolved, but the discussion can continue if something comes up.

traq
09-21-2013, 02:05 AM
After several calls to GoDaddy they finally aditted that where my email resides on the server the que is jammed and I just have to wait. Thank you for your help.
Sucks!

Though it does point out that, just because mail() is successful, it doesn't mean your email was actually sent...!


That's very strange. I wouldn't be surprised by a 5 minute delay, or maybe even a one time delay of an hour or two, but to have it down for long enough to have this whole conversation... I suppose, possible that someone was abusing the email services on that server. Maybe that shut it down for everyone.

It is possible. Someone on the same shared host as one of my sites got the mail server blacklisted for spam once. Took more than a whole day to resolve it (and I don't even know how long it was "broken" before I noticed).

On the other hand, I also don't place GoDaddy in the "most reliable web hosts" category - and, as Daniel says, their customer service/ tech support is bad. At the end of the day, pricing is really their only selling point.

djr33
09-21-2013, 02:31 AM
On the other hand, I also don't place GoDaddy in the "most reliable web hosts" category - and, as Daniel says, their customer service/ tech support is bad. At the end of the day, pricing is really their only selling point.For the record, I use GoDaddy. And they have good prices and everything is fine unless something goes wrong. It's rare that something goes wrong. And when it does, they are bad at solving it and even worse at the tech support side of things. Once I upgraded my account to a more expensive plan and then found all of my files missing-- it took them a week or so to get the backup uploaded from the magnetic tape stored in some secret location such that it was inaccessible for 7 days :p
But more on topic... this is the kind of thing GoDaddy should be able to handle. They are generally reliable and sending email is a basic function. They also have given me credits in the past for any issues like this, so although it can be annoying it all balances out for me. And the price is right. If I had the time to shop around, I can't say that I'd have any problem moving, though.

traq
09-21-2013, 04:10 AM
Yeah. Most hosts fall into the same general class as GoDaddy - cheap, more than suitable for most situations, everything works great unless it doesn't. Story of shared hosting.

Better alternatives exist, but they're expensive. :)