SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member razor_sharp's Avatar
    Join Date
    Feb 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with a contact submit form

    Hello all,

    I'm having trouble with a contact form I use on one of my sites. The fields include Name, Email Address, Phone Number, and Comments. Whenever I fill out the fields and press submit my confirmation page shows fine, but I never receive the info to my email address. My code is as follows:

    my contact page,
    HTML Code:
    <form action="mailer.php" method="post">
    
    	  <fieldset>
    	  <legend> Contact Us</legend>
    	  <ol>
    	  <li>
    	  <label for="name">Name</label>
    	  <input id="name" name="name" class="text" type="text" />
    	  </li>
    <li>
    <label for="email"> Email address </label>
    <input id="email" name="email" class="text" type="text" />
    </li>
    <li>
    <label for="phone"> Phone Number</label>
    <input id="phone" name="phone" class="text" type="text" />
    </li>
    <li>
    
    <label for="for""comments">Comments</label>
    <textarea name="comments" cols="50" rows="2" wrap="virtual" class="text" id="comments"></textarea>
    </li>
    </ol>
    
    </fieldset>
    
    <fieldset class="submit">
    <input class="submit" type="submit"
    value="Submit" />
    </fieldset>
    </form>
    mailer.php
    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "tim@yahoo.com";
    $subject "Website Comments";
    $name_field $_POST['name'];
    $email_field $_POST['email'];
    $phone_field $_POST['phone'];
    $comments $_POST['comments'];
     
    $body "From: $name_field\n E-Mail: $email_field\n Phone Number: $phone_field\n Comments:\n $comments";
     
    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    } else {

    echo 
    "Thanks for your message!";

    }
    ?>
    Thanks for any help

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace:

    PHP Code:
    echo "Data has been submitted to $to!";
    mail($to$subject$body); 
    with:

    PHP Code:
    if (mail($to$subject$body))
    {
        echo 
    "Data has been submitted to $to!";
    }
    else
    {
        echo 
    "Email error";

    to see if email actually ever goes out.

  3. #3
    SitePoint Member razor_sharp's Avatar
    Join Date
    Feb 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i switched it to

    PHP Code:
    else 
    {
    echo 
    "Email error";

    instead of

    PHP Code:
    else 
    {
    echo 
    "Thanks for your message!";

    That was a mistake on my part cause I was defining a failed submit as "Thanks for your message"

    Now that it has been switched it says "Email error" so the email is NOT going out.

    Any further suggestions?

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you running this script on your development machine? If so, you'll have to install and configure mail server.

    If you're running on some web host, you may have to check their forums/wiki/knowledge base to see if they put some restrictions on sending email.

    Alternatively you can try sending mail using SMTP, I would suggest using PHPMailer class for that. Here's an example on how to use it: http://phpmailer.codeworxtech.com/in...?pg=tutorial#2

  5. #5
    SitePoint Addict aguroyz's Avatar
    Join Date
    Jan 2009
    Location
    Konoha Fire Country
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the error that your input type submit does not have a name = 'submit' attribute... Just a wild guess though..
    Uniquely FILIPINO... See how talented and creative Filipinos are.
    http://www.smalltym.com
    Custom Web Designs:
    http://proweaver.com

  6. #6
    SitePoint Member razor_sharp's Avatar
    Join Date
    Feb 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by STeeL_LT View Post
    Are you running this script on your development machine? If so, you'll have to install and configure mail server.

    If you're running on some web host, you may have to check their forums/wiki/knowledge base to see if they put some restrictions on sending email.

    Alternatively you can try sending mail using SMTP, I would suggest using PHPMailer class for that. Here's an example on how to use it: http://phpmailer.codeworxtech.com/in...?pg=tutorial#2
    I will check into this info and post again in this thread if I'm still having trouble. Thanks for your help.


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
  •