SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Email contact form not working

    Hi guys,
    I just helped a friend transfer their site over to a new server. They had a email contact form on there that no longer works since the move. I got all the other aspects of the site that use php working just fine but for some reason this email form will not cooperate. I'm not much of a php guy, so I figured someone on here might be able to help me out. The form doesn't display at all.

    Here is the code that emails the form(I changed the email address to a generic one for purposes of posting here):
    PHP Code:
          <?php
    if(!isset($_POST['send'])) {
        
    // initiate variables
        
    $name            '';
        
    $email            '';
        
    $message        '';
        
    // error messages
        
    $namemsg        '';
        
    $emailmsg        '';
    }
        
    // Gets the date and time from your server
        
    $date date("m/d/Y H:i:s"); 

    //if form sent do these things
    if(isset($_POST['send'])) {    
        
    //get data
        
    $name        $_POST['name'];
        
    $email        $_POST['email'];
        
    $message    $_POST['message'];
        
        
    //check for errors    
        
    if(trim($name) == '') {
            
    $namemsg 'active';
        } 
        if(
    trim($email) == '') {
            
    $emailmsg 'active';
        }
        else if(!
    isEmail($email)) {
            
    $emailmsg 'active';
        }
        
        
    // if no errors ... send mail
        
    if($namemsg == '' && $emailmsg == '') {
            if(
    get_magic_quotes_gpc()) {
                
    $message stripslashes($message);
            }    
        
        
    // the email will be sent here
        
    $to "email@mail.com";
        
        
    // the email subject ( modify it as you wish )
        
    $subject "Website Visitor Information";
        
        
    // the mail message ( add any additional information if you want )
        
    $msg "Visitor Information\n";
        
    $msg.= "------------------------------\n";
        
    $msg.= "Name: $name\n";
        
    $msg.= "Email: $email\n";
        if(
    $message != "") {
            
    $msg.= "\nComments/Questions:\n";
            
    $msg.= "------------------------------\n";
            
    $msg.= "$message\n\n";
            
    $msg.= "Date/Time: $date"
        }
        
    //This sends a confirmation to your visitor
        
    mail ("$email","Thanks your comments"
        
    "Hi $name,\n
    Thanks for filling out our online form! We have received your message and will get back to you as soon as possible.\n

    Thank you \n"
    "From: email@mail.com\r\nReply-to: email@mail.com\r\n"); 
            
            
    mail($to$subject$msg"From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
        }
    }
    ?>
          <?php
    if($namemsg != '' || $lnamemsg != '' || $companymsg != '' || $emailmsg != ''
         { 
            
    $errors "true";
            echo 
    "<div class=\"alertMsg\">Please check the highlighted areas for errors. 
        </div>"
    ;
         }
        
    if(isset(
    $_POST['send']) && $errors != "true") {    
    ?>
          <div class="thanksMsg">
            <h3>Thank You! Your message has been sent.<br />
              An email confirmation has been sent to your email address.</h3>
          </div>
          <?
    } else {

    ?>
    Here is the form code:
    PHP Code:
    <form method="post" action="" id="contactform" name="contactform">
            <dl>
              <dt>
                <label for="name">Name:</label>
                <em>* </em></dt>
              <dd> <span <?php if($namemsg == "active") echo "class=\"errmsg\""?>>
                <input name="name" id="name" type="text" value="<?php echo "$name";?>" />
                </span></dd>
              <dt>
                <label for="email">Email Address:</label>
                <em>* </em></dt>
              <dd> <span <?php if($emailmsg == "active") echo "class=\"errmsg\""?>>
                <input id="email" name="email" type="text" value="<?php echo "$email";?>" />
                </span> </dd>
              <dt class="wide">
                <label for="comments">Comments:</label>
              </dt>
              <dd>
                <div class="clear"></div>
                <textarea name="message" cols="25" rows="6" wrap="virtual" id="message"><?php echo "$message";?>
    </textarea>
              </dd>
            </dl>
            <p>
              <input type="submit" name="send" alt="Submit" value="Submit" title="Submit" />
            </p>
            <p><strong>Note:</strong> Fields marked with an <em>*</em> are required.<br /><strong>Disclaimer:</strong> TnT will not sell, trade, send, or disclose any of your personal information, name, email address, or comments to any 3rd party vendors. You will not be signed up for any spam or mailing lists either!</p>
          </form>
    then there is this bit of code after the form tag:
    PHP Code:
          <?php
    }

    function 
    isEmail($email) {
        return(
    preg_match('/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i',$email));
    }
    ?>
    As I said above, the form doesn't even display on the new server at all. It worked fine on the old server, and works fine on my development server. Could it be something with the php settings on the new server? Or does there appear to be an obvious error in the code?

    Thanks in advance!

  2. #2
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The form display does not depend on php, however processing does. So if the form is not displaying the problem is elsewhere. Did you try loading up the form page without any php code in to a browser locally ?

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I mentioned, it worked fine on the server it was on before the move, and it works just fine on my local development server. it only doesn't work on the new server it is hosted on.
    I did not write the code myself and I am new to php, I usually develop in coldfusion.
    But since it works locally, and it worked on the server it was previously hosted on I thought it may be something with the php settings on the new server. If that is the case, then I can just submit a trouble ticket to the new host. I was hoping if that is the case, someone here might be able to suggest what setting it would be so that I could submit a more detailed trouble ticket.
    I realize it could be the code, but it seems to work fine everywhere else except for on the server it resides on. So I'm completely lost...

  4. #4
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can see that in your form code are some ; signs missing at the end of some php lines. I added them:

    PHP Code:
    <form method="post" action="" id="contactform" name="contactform">
            <dl>
              <dt>
                <label for="name">Name:</label>
                <em>* </em></dt>
              <dd> <span <?php if($namemsg == "active") echo "class=\"errmsg\"";?>>
                <input name="name" id="name" type="text" value="<?php echo "$name";?>" />
                </span></dd>
              <dt>
                <label for="email">Email Address:</label>
                <em>* </em></dt>
              <dd> <span <?php if($emailmsg == "active") echo "class=\"errmsg\"";?>>
                <input id="email" name="email" type="text" value="<?php echo "$email";?>" />
                </span> </dd>
              <dt class="wide">
                <label for="comments">Comments:</label>
              </dt>
              <dd>
                <div class="clear"></div>
                <textarea name="message" cols="25" rows="6" wrap="virtual" id="message"><?php echo "$message";?>
    </textarea>
              </dd>
            </dl>
            <p>
              <input type="submit" name="send" alt="Submit" value="Submit" title="Submit" />
            </p>
            <p><strong>Note:</strong> Fields marked with an <em>*</em> are required.<br /><strong>Disclaimer:</strong> TnT will not sell, trade, send, or disclose any of your personal information, name, email address, or comments to any 3rd party vendors. You will not be signed up for any spam or mailing lists either!</p>
          </form>
    if this doesn't fix it. try adding the following line at the top to show the exact error:
    PHP Code:
    error_reporting(E_ALL); 
    Last edited by fristi; Jun 22, 2009 at 09:55. Reason: darn typos
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the response fristi!
    I updated the form code with your suggestion, and no luck.

    I was unsure where in the document to post this, but I put the following at the very beginning of the document and it did not display any results.
    PHP Code:
    <?php 
    error_reporting
    (E_ALL); 
    ?>
    Is that the correct way and place to insert that?

    Thank you!

  6. #6
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sikk66 View Post
    thanks for the response fristi!
    I updated the form code with your suggestion, and no luck.

    I was unsure where in the document to post this, but I put the following at the very beginning of the document and it did not display any results.
    PHP Code:
    <?php 
    error_reporting
    (E_ALL); 
    ?>
    Is that the correct way and place to insert that?

    Thank you!

    I tried to run your script you gave on my test server and he said that there are some undefined variables in this line:

    PHP Code:
    if($namemsg != '' || $lnamemsg != '' || $companymsg != '' || $emailmsg != ''
    he doesn't know $lnamemsg and $companymsg.

    Did you define them elsewhere?



    you put the error_reporting on the right place.
    I think it is because your host has also disabled displaying them.

    you could try:

    PHP Code:
    ini_set('display_errors',1);
    error_reporting(E_ALL); 
    be sure to remove those lines afterwards. Otherwise they could output unwanted info to hackers.
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that same line seems to be throwing an error. I got the following results after telling it to display errors:

    Notice: Undefined variable: lnamemsg in /usr/home/tntska/www/htdocs/contact.php on line 98

    Notice: Undefined variable: companymsg in /usr/home/tntska/www/htdocs/contact.php on line 98


    In the first post I included ALL of the code that has to do with this form. I do not see these defined anywhere else in there in the document.

    Strangely enough, this code works fine on my server, just not the server it needs to work on.

    Any suggestions?

  8. #8
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried removing the following code as those aren't form fields in my form and it appeared to be what was throwing the error:
    PHP Code:
    $lnamemsg != '' || $companymsg != '' || 
    But still no luck...

  9. #9
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to everyone for your responses. I just went ahead and used some new code, so I got it up and running.

    Thanks again!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •