Jump to content

HTML and PHP Email Form Not showing information

wolfslab

I have this PHP code runnung on a web server and it does send an email to me but it doesnt show the message, name, or email from the user. Here is the code.

 

PHP:

<?php
    // Grabbing data sent from the form and assigning it to variables
    $field_name = $_POST['name'];
    $field_email = $_POST['email'];
    $field_message = $_REQUEST['msg'];
    
    foreach($_POST['check'] as $value) {
        $check_boxes .= $value." ";
    }
    
    $radio_button = $_POST['cf_radio_button'];
    $drop_down_item = $_POST['cf_drop_down'];
    
    // Composing body of the message
    $mail_to = 'example@example.com';
    $subject = 'Message from a site visitor '.$field_name;
    
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message."\n";
    
    // Creating headers of the message
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
    
    if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
history.back(1);
</script>
<?php
    }
    
    else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to austingazur@yahoo.com');
history.back(1);
</script>
<?php
    }
    ?>

HTML

<footer id="footer">
      <div class="inner">
    
            
            <h2>Contact Me</h2>
        
        <form action="contact.php" method="post">
         
 
            <div>
                <label for="name">Name:</label>
                <input type="text" id="name" name="user_name" />
            </div>
            <div>
                <label for="mail">E-mail:</label>
                <input type="email" id="mail" name="user_mail" />
            </div>
            <div>
                <label for="msg">Message:</label>
                <textarea id="msg" name="user_message"></textarea>
            </div>
            <div class="button">
                <button type="submit">Send your message</button>
            </div>
        </form>

 

Link to comment
Share on other sites

Link to post
Share on other sites

where is the message not showing.  on a result page or in the email body of the sent message?

"Cheapness is not a skill"

Link to comment
Share on other sites

Link to post
Share on other sites

if it is the the result page the you need to enter a value= option in your <input> & <textarea> tags.

 

<input type="text" value="'.$php_field_value.'">

"Cheapness is not a skill"

Link to comment
Share on other sites

Link to post
Share on other sites

I have a stupid question. When you are validating a form with PHP, do you  put the PHP validation's on a different file and link it to the html file that needs the validating?

Again stupid question.

Link to comment
Share on other sites

Link to post
Share on other sites

// Grabbing data sent from the form and assigning it to variables
$field_name = $_POST['user_name'];
$field_email = $_POST['user_mail'];
$field_message = $_POST['user_message'];

You need to use the name attribute when calling over form submit.

 

As for a separate validation file, why not just use the same file? I don't see anything wrong with that. I suppose if you are making your validation function or a class to be callable elsewhere, sure if not I don't see the need. 

 

Hope it helps

Link to comment
Share on other sites

Link to post
Share on other sites

it's probably also due to the history.back I would create a php session that holds the error or success then redirects back to the form. On the top of the form page you have a if(isset($_session['name here']))

 

this will allow the message to display if it exists. Just unset the session inside the if when coming back to the page they don't see the message for a second time.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, davidna2002 said:

if it is the the result page the you need to enter a value= option in your <input> & <textarea> tags.

 

<input type="text" value="'.$php_field_value.'">

I've tried putting that in and it didn't work. On the email I receive, it just has this:

From: 
E-mail: 
Message: 

 

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, Sergio45 said:

I have a stupid question. When you are validating a form with PHP, do you  put the PHP validation's on a different file and link it to the html file that needs the validating?

Again stupid question.

I just put in validation code in my HTML. Here is the code:

<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, davidna2002 said:

did you get it working?

No, not yet.

Link to comment
Share on other sites

Link to post
Share on other sites

If you set the variables to a fixed value, do they then show up in the email? If they do, could you output a var_dump() of the variables and post it here?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×