My contact form sends blank body_messages
Asked Answered
P

1

6

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!

Pahang answered 12/10, 2012 at 12:58 Comment(13)
I can send Emails but they show up like this: From: nothing, Company: nothing, Email: nothing, message: nothing all emptyPahang
it's not the code, check the php.ini or server config, because i just copypasted your code into my server and it works.Pokey
I dont understand? Im a noob, php.ini or server config? explain a litte pleasePahang
@Pokey please help me, you say its is working but why dont I get anything from my form fields like name, message?Pahang
@user1741191 It just works, try to upload the script to a server and run it from there, by the way, the $email = filter_input(); is wrong, because if the filtering fail, it returns false instead of the email address, correct way would be: if(!filter_input(...)){$email = .....Pokey
@Pokey I have uploaded the form and yes it works but my form fields send nothing... I only get from:, email:, message:, and that is why I need help...Pahang
www.findersandsellers.com/test.php try it there and tell me if it works, i will leave it open only for a while okPokey
@Pokey thank you, but where does my message go?Pahang
I set it up so it goes to the same address you have in your code, i have already tested on my address and it worked well. My server is pretty new so remember to check the spambox in case it goes therePokey
@Pokey omg please set it to [email protected] the other one is wrongPahang
I set it to both your and my email, so i just got your testing email as well, e-mail: a.el**********[email protected], message: hejsa, so the code is working, I copypasted without any change. So check your php.ini configuration or mailserver xDPokey
You are welcome, I am removing the script from my server for security now that you checked that it work ok? If I think up what it can be i will reply to youPokey
I got your message to my email 1 min agoPahang
S
2

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
Simons answered 12/10, 2012 at 13:8 Comment(9)
I will try that asap and come back to you. Thank youPahang
Its still empty, the fields I fill in on my form: Name, Company, Email and message are still not showing,Pahang
@user1741191 Did you remove the value="" part?Simons
@user1741191 After removing it,check the post values in kontakt.php.. check the edit in the answerSimons
@user1741191 If you can't see them,then the problem is with the form submissionSimons
not really sure what I should be looking for when you say post valuesPahang
@user1741191 Check my anser again.. Add the echo part which is present in the editSimons
I deleted my php from the server and uploaded it again, now I cant send the Email anymore... good sign?Pahang
The form says that the message is delivered but I dont get anything, not even the empty fieldsPahang

© 2022 - 2024 — McMap. All rights reserved.