Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My contact form sends blank body_messages

I’m new to PHP so bear with me. My form is sending empty emails when I press submit. Any help would be great.

This is my form:

    <form class="contact_form" action="kontakt.php" method="post">
        <p><input type="text" required="required" id="name" name="name" class="text_input" value="" size="22"  />
        <label for="name">Namn *</label></p>

        <p><input type="text" required="required" id="company" name="company" class="text_input" value="" size="22"  />
        <label for="company">Företag *</label></p>

        <p><input type="email" required="required" id="email" name="email" class="text_input" value="" size="22"  />
        <label for="email">Epost *</label></p>

        <p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>

        <p><button type="submit" class="button white"><span>Skicka</span></button></p>
        <input type="hidden" value="[email protected]" name="contact_to"/>
    </form>

And my PHP code so far is:

<?php

$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];



$mail_to = '[email protected]';

$subject = 'Lilla form'.$name;



$body_message = 'From: '.$name."\n";

$body_message .= 'E-mail: '.$email."\n";

$body_message .= 'Message: '.$content;



$headers = 'From: '.$email."\r\n";

$headers .= 'Reply-To: '.$email."\r\n";



$mail_status = mail($mail_to, $subject, $body_message, $headers);

?>

Please help me, I’m really stuck.

Thank you all!

like image 917
Abel Avatar asked Oct 12 '12 12:10

Abel


People also ask

Why is contact form not working?

You need to make sure that you've set a valid email address in the widget's settings. Check your browser's error console for Javascript errors, and fix them if you have any. If you are an Elfsight form widget user and have a WordPress version of the widget, then check that your server supports mail function.

What does a blank automatic reply email mean?

If Mail is open, and someone replies to a message, a blank reply is auto sent back to the sender.

Does Contact Form 7 work on localhost?

So, i knew that when using CF7 on localhost was unable to send email to your mail box. It wasn't the first time i'm using CF7, so i know that you still can test out the form and it will able to show up a successful green border message and said that your message was successful sent.


1 Answers

Try this

 <form class="contact_form" action="kontakt.php" method="post">
    <p><input type="text" required="required" id="name" name="name" class="text_input" size="22"  />
    <label for="name">Namn *</label></p>

    <p><input type="text" required="required" id="company" name="company" class="text_input" size="22"  />
    <label for="company">Företag *</label></p>

    <p><input type="email" required="required" id="email" name="email" class="text_input"  size="22"  />
    <label for="email">Epost *</label></p>

    <p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>

    <p><button type="submit" class="button white"><span>Skicka</span></button></p>
    <input type="hidden" value="[email protected]" name="contact_to"/>
</form>

Edit:(Debug)

$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];

echo $name.$comapny.$email.$content;exit; // check whether the values are posted successfully or not
like image 136
Bhuvan Rikka Avatar answered Sep 29 '22 19:09

Bhuvan Rikka