PHP form sends out blank messages

Hello everyone,

I have an email form in my website and when I try to send a message using the form it does send something but the message I receive is blank, there is nothing in it, no name, no email, no subject and no message!! I have no experience using PHP, so I don’t really know what to change in my code. The code came with a template I downloaded online. All the HTML code seems to work fine, so I believe the issue comes from the PHP code. Please help!!!

This is my code:

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                <div class="col-sm-5 col-sm-offset-1">
                    <div class="form-group">
                        <label>Name *</label>
                        <input type="text" name="name" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Email *</label>
                        <input type="email" name="email" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Phone</label>
                        <input type="number" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>Company Name</label>
                        <input type="text" class="form-control">
                    </div>                        
                </div>
                <div class="col-sm-5">
                    <div class="form-group">
                        <label>Subject *</label>
                        <input type="text" name="subject" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Message *</label>
                        <textarea name="message" id="message" required class="form-control" rows="8"></textarea>
                    </div>                        
                    <div class="form-group">
                        <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
                    </div>
                </div>
            </form>



<?php

header('Content-type: application/json');
$status = array(
	'type'=>'success',
	'message'=>'Thank you for contact us. As early as possible  we will contact you '
);

$name = trim(stripslashes($_POST['name'])); 
$email = trim(stripslashes($_POST['email'])); 
$subject = trim(stripslashes($_POST['subject'])); 
$message = trim(stripslashes($_POST['message'])); 

$email_from = $email;
$email_to = 's.design.mg@gmail.com';//replace with your email

$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;

$success = mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

echo json_encode($status);
die;
?>

You have shown both in the same file. I assume that the PHP is actually in a separate file named sendemail.php.

Have you tried dumping the content of $_POST to check what values are actually getting to the sendemail.php file from the form?

Hello felgall!
Thank you for your input. Yes the PHPis in a separate file called sednmail.php.
Regarding the $_POST I don’t know what to do with it as I have zero experience with PHP
Would you be kind to tell me what to do with it?

if you add var_dump($_POST); at the top of the page it should disply the values passed in that array to confirm whether the problem is before it gets there or after.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.