First time using PHP, contact form only sending blank emails? Help!

Discussion in 'PHP' started by christoffrrr, Aug 21, 2014.

  1. #1
    Hey guys, just wondering if you can help. I use alot of HTML and CSS. im just starting on jquery and PHP now. I am more of a designer than a coder, however I would like to be strong at both.

    I made a simple contact form, this is the HTML

    <form action="forum_process.php" method="post">
    
      <p>first name
      <input name="first_name" type="text" id="first_name">
      
      <p>
      last name <input name="last_name" type="text" id="last_name">
      <p>
      email <input name="email" type="text" id="email">
      <p>
      message
      <textarea name="message " id="message "></textarea>
      <p>
      <input name="submit" type="submit" id="submit">
      <input name="reset" type="reset" id="reset">
    
    </form>
    Code (markup):

    and this is the PHP:

    <?php
    
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $to = "christoffchisholm@gmail.com";
    $subject = "new message";
    
    mail ($to, $subject, $message, "from: " . $first_name . $last_name);
    echo "your message has been sent";
    
    ?>
    PHP:
    I've googled but i just can't find the reason why, it sends the email, but it comes up completely blank. Very frustrating. Just when I thought I was getting somewhere.

    I would greatly appreciate the help, also the email address it sends through is really werid. and it sends it to spam and says its untrusted and blocks it. Thanks guys,
     
    christoffrrr, Aug 21, 2014 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,897
    Likes Received:
    4,553
    Best Answers:
    123
    Trophy Points:
    665
    #2
    There are extra parameters you can send through to set the sender. Check out php.net/mail
    Because you haven't told who sent the email it just works out a default sender email from the server. Your spam filter recognises the default as a default and isn't impressed.

    Your form is pretty insecure and you will get spammed through it and some of it will be ugly. You may want to build some rules around what the message has to look like before you will send it. Things like no more than 1 hyperlink in the message, a local IP address.
     
    sarahk, Aug 21, 2014 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Although the spam-filter might wreak havoc based on the missing sender-email, but that doesn't really explain the empty received email.
    The HTML-code isn't very good either, since you're missing label-tags etc.
    What you should do is comment out the mail()-function, and just try to output the content arriving from the form - just do a print_r($_POST) and check to see if everything is arriving.
     
    PoPSiCLe, Aug 21, 2014 IP
  4. hangbowl

    hangbowl Well-Known Member

    Messages:
    228
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    143
    Digital Goods:
    2
    #4
    how about fix this. see at the textarea.
    <textarea name="message " id="message "></textarea>
    HTML:
    at the name parameter, the value had space on it. try to remove it.
     
    hangbowl, Aug 22, 2014 IP
    ThePHPMaster likes this.
  5. abhicyco

    abhicyco Active Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #5
    As a standard practice add mailing headers while using PHP mail function.
     
    abhicyco, Aug 27, 2014 IP