Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Contact form

    Hello,

    I have the below contact.php file, and it is not sending emails to myself (nell@example.com). I was wondering if someone could help...? Much appreciated.

    Nell

    PHP Code:
    <?php

    if(!$_POST) exit;

    $email $_POST['email'];

    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
        
    $error.="Invalid email address entered";
        
    $errors=1;
    }
    if(
    $errors==1) echo $error;
    else{
        
    $values = array ('name','email','message');
        
    $required = array('name','email','message');
         
        
    $your_email "nell@example.com";
        
    $email_subject "New Message: ".$_POST['subject'];
        
    $email_content "new message:\n";
        
        foreach(
    $values as $key => $value){
          if(
    in_array($value,$required)){
            if (
    $key != 'subject' && $key != 'company') {
              if( empty(
    $_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
            }
            
    $email_content .= $value.': '.$_POST[$value]."\n";
          }
        }
         
        if(@
    mail($your_email,$email_subject,$email_content)) {
            echo 
    'Message sent!'
        } else {
            echo 
    'ERROR!';
        }
    }
    ?>
    Last edited by VIPStephan; 01-08-2012 at 03:19 PM. Reason: wrapped PHP BB tags

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Do you get the "message sent" print our or the "ERROR" print out? Also remove the @ from @mail. It is suppressing any errors that mail is giving back. Also check your spam box.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply. I am getting the 'message sent' - no errors, though it's just not coming to my email inbox...

    Have also removed the '@'.... and checked spam.

    This is my form:

    <form action="contact.php" method="post" id="contactform">
    <ol>
    <li>
    <label for="name">First Name <span class="red">*</span></label>
    <input id="name" name="name" class="text" />
    </li>
    <li>
    <label for="email">Your email <span class="red">*</span></label>
    <input id="email" name="email" class="text" />
    </li>
    <li>
    <label for="email">Phone </label>
    <input id="email" name="email" class="text" />
    </li>
    <li>
    <label for="company">Company</label>
    <input id="company" name="company" class="text" />
    </li>
    <li>
    <label for="subject">Subject</label>
    <input id="subject" name="subject" class="text" />
    </li>
    <li>
    <label for="message">Message <span class="red">*</span></label>
    <textarea id="message" name="message" rows="6" cols="50"></textarea>
    </li>
    <li class="buttons">
    <div class="clr">
    <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
    </div>
    </li>
    </ol>
    </form>

    Is this correct?

    thanks.
    Last edited by nell; 01-08-2012 at 06:18 PM.

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by nell View Post
    Thanks for the reply. I am getting the 'message sent' - no errors, though it's just not coming to my email inbox...

    Have also removed the '@'.... and checked spam.

    This is my form:

    <form action="contact.php" method="post" id="contactform">
    <ol>
    <li>
    <label for="name">First Name <span class="red">*</span></label>
    <input id="name" name="name" class="text" />
    </li>
    <li>
    <label for="email">Your email <span class="red">*</span></label>
    <input id="email" name="email" class="text" />
    </li>
    <li>
    <label for="email">Phone </label>
    <input id="email" name="email" class="text" /> </li>
    <li>
    <label for="company">Company</label>
    <input id="company" name="company" class="text" />
    </li>
    <li>
    <label for="subject">Subject</label>
    <input id="subject" name="subject" class="text" />
    </li>
    <li>
    <label for="message">Message <span class="red">*</span></label>
    <textarea id="message" name="message" rows="6" cols="50"></textarea>
    </li>
    <li class="buttons">
    <div class="clr">
    <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
    </div>
    </li>
    </ol>
    </form>

    Is this correct?

    thanks.
    Shouldn't that bolded input be name="phone"? Also, you've not defined types for your input fields in the form. Go back and put type="text" in all of them. I don't know how this would effect POST info (might not).

    Regardless, is this correct? or did you censor your email for the post:
    PHP Code:
    $your_email "nell@example.com"
    Ask your hosting provider if there's a mail server error log you can view - that will tell you specifically what's wrong. I'm not entirely sure if you can have the ':' in the subject line without escaping it, but I could be wrong on that. Check your error log for more information. If you're getting the message sent echo, PHP is returning true for the mail function which means everything's alright PHP wise. This is misleading though, as PHP only knows if it's sent the information to the mail server - it doesn't know if the mail server has actually been able to send the mail.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.


  •  

    Posting Permissions

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