Please help me troubleshoot

I am doing website maintenance for a client who had another designer design the site. I am having a hard time figuring out why the contact form is not working on my client’s website. It says it is sent when you click submit but, we never receive the email. The email is working fine as I have sent an email to that email from my personal acct and it works. I also have uploaded a sample form script and that sends right away. So I know it has to be the script. Can someone please look at the code and tell me what I need to fix. Thanks.

[php]

            <!-- The contact form starts from here-->
            <?php
                 $error    = ''; // error message
                 $name     = ''; // sender's name
                 $email    = ''; // sender's email address
                 $subject  = ''; // subject
                 $message  = ''; // the message itself
                  

            if(isset($_POST['send']))
            {
                 $name     = $_POST['name'];
                 $email    = $_POST['email'];
                 $subject  = $_POST['subject'];
                 $message  = $_POST['message'];
                  

                if(trim($name) == '')
                {
                    $error = '<div class="errormsg">Please enter your name!</div>';
                }
                   else if(trim($email) == '')
                {
                    $error = '<div class="errormsg">Please enter your email address!</div>';
                }
                else if(!isEmail($email))
                {
                    $error = '<div class="errormsg">You have enter an invalid e-mail address. Please, try again!</div>';
                }
                   if(trim($subject) == '')
                {
                    $error = '<div class="errormsg">Please enter a subject!</div>';
                }
               else if(trim($message) == '')
                {
                    $error = '<div class="errormsg">Please enter your message!</div>';
                }
                
                    if(get_magic_quotes_gpc())
                    {
                        $message = stripslashes($message);
                    }

                    // the email will be sent here
                    // make sure to change this to be your e-mail
                    $to      = "*******@farrbetterplumbing.com";

                    // the email subject
                    // '[Contact Form] :' will appear automatically in the subject.
                    // You can change it as you want

                    $subject = '[Contact Form] : ' . $subject;

                    // the mail message ( add any additional information if you want )
                    $msg     = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n\n" . "Message : \r\n$message";

                    mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
               }

            ?>

                  <!-- Message sent! (change the text below as you wish)-->
                  <div style="text-align:center;">
                    <h1>Congratulations!!</h1>
                       <p>Thank you <b><?=$name;?></b>, your message is sent!</p>
                  </div>
                  <!--End Message Sent-->


            <?php
               
            if(!isset($_POST['send']) || $error != '')
            {
         }
            ?>[/php]

Well, overall, I think your code is correct.

But, what does “isEmail” function do? It is not listed…

Also, have you used “echo” to show each item just before you mail it to make sure that each is loaded correctly? I would do that to make sure you have usable data…

Good luck.

To be honest I am not sure what the “isEmail” function is or the echo because I am just taking over the website. so if you can be more specific thanks

So, are you saying you do not know any PHP?

As far as the “isEmail” goes, you are using it in the code you showed as a “function”.
Such as “isEmail(something);” So, it call a function somewhere else in your code.
I do not see it in the post you started with. It may be causing the email to not be sent.

As far as the “echo” goes, that means to PRINT the various variables and see what the values
are to see if they are valid ones. To do this, just before the “mail()” function, you need to display
the variables to see what is happening… Use the echo/print command: “echo(variable);”…
Something like this:
echo("\r\n$to=" . $to);
echo("\r\n$subject=" . $subject);
echo("\r\n$email=" . $email);
echo("\r\n$msg=" . $msg);
die(“Email cancelled temporarily…”);
Place this just before the mail() line and it will display the data in these variables, then stops. In this manner, you can see what is being placed into the email function. If these are not accurate, then, you can look at the code for the bad one.

Another debugging tool would be to checking how far the code actually goes. You can print something like “Got Here!” using echos and follow the code in your IF clauses to see where it is dying.
echo(“Got Here!”);
die(“temp stop…”);
This can be placed in one spot and it if comes up, you know your code is working up to that point.
You can put it into IF’s and see if one of them is causing the problem…

So, there are some steps for you to look into. Good luck with your testing…

I do not write my own scripts but I can understand it.

I copied the echos that you put and ran the code and it still says the message is sent and nothing else showed up.

Okay, so what was in the variables? Are they all correct for an email? Where does your code stop?

Perhaps I was not clear… You code is designed to get data from your form page, then do some PHP processing, then display some HTML saying “MESSAGE WAS SENT”, then, do some PHP processing and send it all to the browser to be “rendered”.

So, your process will ALWAYS say the message was sent. Did you get an error message? When you placed the GOT-HERE two-line-debug-code inside the first IF clause, did it get there? When you moved those two lines to the second IF clause did it get there? You have to move your debug displays around until you find where it is not working. One of your IF clauses is malfunctioning… Try harder to find which one.

My guess is that since you never closed any of the first IF’s, that may be your problem…
IF (cond){
do something…
}elseif(cond2){
do something2…
}elseif(cond3){
do something3…
}else{ //this is missing…(Normally where the SEND EMAIL would be…)
do somehting if all others do not do something…
}

the culprit may not be the script. It could very well be the email server thinking its spam. I’ve had that happen on serval occassions. Also, to clean up the code, put your headers in a header variable. You don’t need to use \r\n inside the message, \n works just fine for a new line.

The way he’s using isEmail looks to be validation. Still would be good to see the code though.

Yep, Richei… Also, HE did not write the script. I didn’t want to fix it for him, thought he would do that.
I just gave him tools to try to debug it…

Here is the complete code. If you tell me what I need to fix than I can do it. Thanks I am new to PHP, and would like to learn more. I typically develop in Wordpress, but have not moved to custom themes. I do customize themes. I can find things in the php to add to it or remove on wordpress. It has been a very long time since I hand coded and this site is hand coded. Thanks for your help.

[php]

        <!-- The contact form starts from here-->
        <?php
             $error    = ''; // error message
             $name     = ''; // sender's name
             $email    = ''; // sender's email address
             $subject  = ''; // subject
             $message  = ''; // the message itself
           	

        if(isset($_POST['send']))
        {
             $name     = $_POST['name'];
             $email    = $_POST['email'];
             $subject  = $_POST['subject'];
             $message  = $_POST['message'];
           	

            if(trim($name) == '')
            {
                $error = '<div class="errormsg">Please enter your name!</div>';
            }
        	    else if(trim($email) == '')
            {
                $error = '<div class="errormsg">Please enter your email address!</div>';
            }
            else if(!isEmail($email))
            {
                $error = '<div class="errormsg">You have enter an invalid e-mail address. Please, try again!</div>';
            }
        	    if(trim($subject) == '')
            {
                $error = '<div class="errormsg">Please enter a subject!</div>';
            }
        	else if(trim($message) == '')
            {
                $error = '<div class="errormsg">Please enter your message!</div>';
            }
          	
                if(get_magic_quotes_gpc())
                {
                    $message = stripslashes($message);
                }

                // the email will be sent here
                // make sure to change this to be your e-mail
                $to      = "*******@farrbetterplumbing.com";

                // the email subject
                // '[Contact Form] :' will appear automatically in the subject.
                // You can change it as you want

                $subject = '[Contact Form] : ' . $subject;

                // the mail message ( add any additional information if you want )
                $msg     = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n\n" . "Message : \r\n$message";

                mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
				}

        ?>

              <!-- Message sent! (change the text below as you wish)-->
              <div style="text-align:center;">
                <h1>Congratulations!!</h1>
                   <p>Thank you <b><?=$name;?></b>, your message is sent!</p>
              </div>
              <!--End Message Sent-->


        <?php
            
        if(!isset($_POST['send']) || $error != '')
        {
		}
        ?>

[/php]

If it were my choice I would use Wordpress and than I know I would not be having these issues lol

I am sorry, but, I do not know how else to say this AGAIN, but…

THIS LINE: else if(!isEmail($email))
calls a function called “isEmail”…

So, your code you posted is NOT complete!

It MUST be set up in your page somewhere. I must be in some PHP code either in the page you posted or in an “include” file. If you can not show us the code for this function, we can not help you. If it is NOT in any “include” file or elsewhere in the page you posted, that is your problem.

So, we need to know if you have this function. Show it to us if you have it. If not, say so and we can help.

That is all the code. he just has the contact.php file and than the rest are the other pages and the css.

Seems like that is for email validation.

Okay, then I searched and found this routine to be part of “WebRootKit”, a utility that some use for validation of there emails to remove code so that hackers and web robots won’t submit code into the email.
So, here is the code I found. You need to add this routine right after the first <?PHP line in your code.

This will complete the function which may be giving you a problem. If not repost again (sorry) with that code in place and we can look at it further. Hopefully this will help fix it…
[php]
// Routine to check email for problems…
function isEmail($email){
return eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email);
}

[/php]

Let us know…

Thank you. I put it where you told me to and still have not received an email from the form submission.

Here is the code:

[php]

        <!-- The contact form starts from here-->
        <?php

// Routine to check email for problems…
function isEmail($email){
return eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email);
}
$error = ‘’; // error message
$name = ‘’; // sender’s name
$email = ‘’; // sender’s email address
$subject = ‘’; // subject
$message = ‘’; // the message itself

        if(isset($_POST['send']))
        {
             $name     = $_POST['name'];
             $email    = $_POST['email'];
             $subject  = $_POST['subject'];
             $message  = $_POST['message'];
           	

            if(trim($name) == '')
            {
                $error = '<div class="errormsg">Please enter your name!</div>';
            }
        	    else if(trim($email) == '')
            {
                $error = '<div class="errormsg">Please enter your email address!</div>';
            }
            else if(!isEmail($email))
            {
                $error = '<div class="errormsg">You have enter an invalid e-mail address. Please, try again!</div>';
            }
        	    if(trim($subject) == '')
            {
                $error = '<div class="errormsg">Please enter a subject!</div>';
            }
        	else if(trim($message) == '')
            {
                $error = '<div class="errormsg">Please enter your message!</div>';
            }
          	
                if(get_magic_quotes_gpc())
                {
                    $message = stripslashes($message);
                }

                // the email will be sent here
                // make sure to change this to be your e-mail
                $to      = "******@farrbetterplumbing.com";

                // the email subject
                // '[Contact Form] :' will appear automatically in the subject.
                // You can change it as you want

                $subject = '[Contact Form] : ' . $subject;

                // the mail message ( add any additional information if you want )
                $msg     = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n\n" . "Message : \r\n$message";

                mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
				}

        ?>

              <!-- Message sent! (change the text below as you wish)-->
              <div style="text-align:center;">
                <h1>Congratulations!!</h1>
                   <p>Thank you <b><?=$name;?></b>, your message is sent!</p>
              </div>
              <!--End Message Sent-->


        <?php
            
        if(!isset($_POST['send']) || $error != '')
        {
		}
        ?>

[/php]

They are using a paid hosting account with awardspace. I can send and receive emails from the email account that the form is set up to receive the submissions.

Well, I am just out of time on this one, so I rewrote it to be more standard.
You can use it or change it or whatever. I basically took all the errors on the validation sections
and corrected them and got rid of the extra code at the end which was not useful.
Hopefully, this will work for you…
[php]

<?php // Routine to check email for problems... function isEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); } $error = ''; // error message $name = ''; // sender's name $email = ''; // sender's email address $subject = ''; // subject $message = ''; // the message itself if(isset($_POST['send'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; // Validate inputs... if(trim($name) == '') { $error = '
Please enter your name!
'; } elseif(trim($email) == '') { $error = '
Please enter your email address!
'; } else if(!isEmail($email)) { $error = '
You have enter an invalid e-mail address. Please, try again!
'; } else if(trim($subject) == '') { $error = '
Please enter a subject!
'; } else if(trim($message) == '') { $error = '
Please enter your message!
'; } // Validation is complete, now contine, if errors display them or send email... if($error != '') { // Error found, display it echo("Errors found in your post:\r\n\r\n"); echo($error); } else { if(get_magic_quotes_gpc()) { $message = stripslashes($message); } // the email will be sent here // make sure to change this to be your e-mail $to = "******@farrbetterplumbing.com"; // the email subject // '[Contact Form] :' will appear automatically in the subject. // You can change it as you want $subject = '[Contact Form] : ' . $subject; // the mail message ( add any additional information if you want ) $msg = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n\n" . "Message : \r\n$message"; mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n") echo(""); echo("
"); echo("

Congratulations!!

"); echo("

Thank you <?=$name;?>, your message is sent!

");
                echo("</div>");
                echo("<!--End Message Sent-->");
			}

}
?>
[/php]
Note: I did not fix all of the error sections. Normally, you would set error messages like this,
$error .= “some error…\r\n”; so it “CONCATS” to the end with a carraige return. So, all of the errors are displayed one after the other… And, no time to test it…

I see an issue with the headers. You’re sending out html email but not specifying it in the headers. I dont’ have time to search it out, but i’ll redo it when i get home.

Thanks I truly appreciate all of the help. I know I need to truly learn php but finding the time is so difficult

Richei, I already gave him all the code… Thanks…

by the way i am a female lol. I replaced the old with the new code and it gave me an error:

Parse error: syntax error, unexpected T_ECHO in /home/www/farrbetterplumbing.com/contact.php on line 225

Sorry, gal, hfischer doesn’t sound female… LOL…

So, is this line 225:
echo(“

Thank you <?=$name;?>, your message is sent!

”);

Try this instead…
echo("

Thank you " . $name . “, your message is sent!

”);

That was bad. As I said, I did not test it as I do not have the rest of the code…
Fix that one and if any other bad ones, post the bad lines… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service