Results 1 to 2 of 2

Thread: PHP Contact process file

  1. #1
    djadejones is offline New Member: Posts Will Be Moderated
    Join Date
    Jun 2011
    Posts
    2

    PHP Contact process file

    Hi guys,
    I have been using the same contact form for all my sites but only recently noticed during tests (and from comments from one of my "clients") that half of the time, emails dont go through.
    I have just put this code in to my new site to test and the contact form processed fine, got me to my success page which then counted down and redirected me to the home page.
    I did this twice and all seemed fine but I still havent had my test emails in my inbox.
    This is the code I use:
    HTML
    Code:
    <form action="processform.php" method="post">
      <label for="name">Name</label><input type="text" id="name" name="name" />
      <label for="email">Email address</label><input type="text" id="email" name="email" />
      <label for="topic">Subject</label><input type="text" id="topic" name="topic" />
      <textarea id="comments" name="comments" rows="5" cols="30"></textarea>
    
      <button type="submit" id="sendmessage">Send</button>
    </form>
    PHP
    Code:
    <?php
    // Pick up the form data and assign it to variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $topic = $_POST['topic'];
    $comments = $_POST['comments'];
    
    // Build the email (replace the address in the $to section with your own)
    $to = 'my e-mail address';
    $subject = "New message: $topic";
    $message = "$name said: $comments";
    $headers = "From: $email";
    
    // Send the mail using PHPs mail() function
    mail($to, $subject, $message, $headers);
    
    // Redirect
    header("Location: success.html");
    I have tried sending to 2 different email addresses, also checked junk mail folders, nothing in there.
    Have also tried amending this bit:
    Code:
    // Build the email (replace the address in the $to section with your own)
    $to = 'my e-mail address';
    $subject = "New message: $topic";
    $message = "$name said: $comments";
    $headers = "From: $email";
    to:
    Code:
    // Build the email (replace the address in the $to section with your own)
    $to = 'my e-mail address';
    $subject = "New message: $topic";
    $message = "$name said: $comments";
    $headers = "From: adey@email.com";
    $headers = "Reply-To: $email";
    so that the email is coming from the email address on my server with the reply-to address having the senders email and still not receiving anything at all!

    Any help appreciated.

    Adey

  2. #2
    Join Date
    Mar 2011
    Posts
    53
    mail is one of the must frustrating functions that i've ever worked with while using php. One day I was testing a form much like this and sometimes i got the email other times I just didn't. About 2 weeks later, I received all my missing emails from 2 weeks earlier. You may try removing the header redirect and see if that helps. I'm not sure that this is your issue, but it might be redirecting before the mail function can finish doing its thing.

    Also, you should always be sanitizing user entered data.

Similar Threads

  1. Killing MySQL process with PHP
    By nyx in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 24 Sep 2010, 09:50 PM
  2. Access external CSS file from PHP file?
    By web88js in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 08 Dec 2007, 07:52 AM
  3. PHP Include: If file not found, can i direct to a default file?
    By ukcoolat in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 04 Nov 2005, 09:47 AM

Posting Permissions

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