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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP For not working properly

    So I've created a php contact form. The problem is, whenever someone would try to send in a contact form, it would send me the labels.. (ie: Name: , Email...) and not their answers. Here's my code...

    PHP CODE:

    Code:
    <?php
        $mail_to = 'email';
    
        $name = $_POST['sender_name'];
    	$email = $_POST['sender_email'];
        $subject = $_POST['sender_subject'];
        $message = $_POST['sender_message'];
     
        $subject = 'Contact ' . $subject;
    
        $body_message = 'From: ' . $name . "\r\n";
    	$body_message .= 'Email: ' . $email . "\r\n";
        $body_message .= 'Subject: ' . $subject . "\r\n";
        $body_message .= 'Message: ' . $message;
    
        $headers = 'From: ' . $mail_from . "\r\n";
        $headers .= 'Reply-To: ' . $mail_from . "\r\n";
     
        $mail_sent = mail($mail_to, $subject, $body_message, $headers);
     
        if ($mail_sent == true){ ?>
            <script language="javascript" type="text/javascript">
            alert('Thank you for contacting us. An Email will be sent to you shortly.');
            window.location = 'website';
            </script>
        <?php } else { ?>
        <script language="javascript" type="text/javascript">
            alert('Message not sent. Please notify the site administrator at email');
            window.location = 'website';
        </script>
        <?php
        }
    ?>


    HTML CODE:

    Code:
    <form action="send-mail.php" id="contactform" method="post">
      <label><b>Name:</b></label><font color="red">*</font><br />
      <input type="text" name="name" id="name" required />
    <br />
      <label><b>Email:</b></label><font color="red">*</font><br />
      <input type="email" name="email" id="email" required />
    <br />
      <label><b>Subject:</b></label><font color="red">*</font><br />
      <input type="subject" name="subject" id="subject" required />
    <br />
      <label><b>Message:</b></label><font color="red">*</font><br />
      <textarea type="message" name="message" id="message" cols="30" rows="3" required ></textarea>
    <br />
    <input type="submit" name="send_message" id="submit" value="Submit" />
    </form>

  • #2
    New Coder
    Join Date
    Nov 2011
    Location
    Ratio, Logic
    Posts
    61
    Thanks
    3
    Thanked 6 Times in 6 Posts
    In your html code, fields are named as name, email, subject and message
    and in php code same ones are named with sender_name, sender_email, sender_subject and sender_message.
    You need same parameters there. Chenge it somewhere to match.
    I.e.
    PHP Code:
    $name $_POST['name'];
    $email $_POST['email'];
    $subject $_POST['subject'];
    $message $_POST['message']; 
    Last edited by Tpojka; 01-30-2014 at 10:33 PM.

  • #3
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Tpojka View Post
    In your html code, fields are named as name, email, subject and message
    and in php code same ones are named with sender_name, sender_email, sender_subject and sender_message.
    You need same parameters there. Chenge it somewhere to match.
    I.e.
    PHP Code:
    $name $_POST['name'];
    $email $_POST['email'];
    $subject $_POST['subject'];
    $message $_POST['message']; 
    Thanks it worked!


  •  

    Posting Permissions

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