9
I’m making a contact form on a website, but the PHP method does not take the value of input in the form, I’ve searched the internet and I can’t find anyone with the same problem.
And e-mail is being sent, the value of the field $subject that I hand come in the email, the rest is not filled.
Follow my form:
<form id="main-contact-form" class="contact-form" method="post" action="sendemail.php" role="form">
    <div class="row">
        <div class="col-sm-6">
            <div class="form-group">
                <input name="contato-nome" id="contato-nome" type="text" class="form-control" required placeholder="Nome">
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <input name="contato-email" id="contato-email" type="email" class="form-control" required placeholder="E-mail">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="form-group">
                <textarea name="contato-mensagem" id="contato-mensagem" required class="form-control" rows="8" placeholder="Mensagem" ></textarea>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-lg">Enviar Mensagem</button>
            </div>
        </div>
    </div>
</form>
Follows the sendmail.php
<?php
header('Content-type: application/json');
$status = array(
    'type'=>'success',
    'message'=>'Email enviado!'
);
$name = @trim(stripslashes($_POST["contato-nome"]));
$email = @trim(stripslashes($_POST["contato-email"])); 
$subject = "E-Mail enviado através do site samamba.com.br"; 
$message = @trim(stripslashes($_POST["contato-mensagem"])); 
$email_from = $email;
$email_to = '[email protected]';
$body = 'Nome: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Assunto: ' . $subject . "\n\n" . 'Menssagem: ' . $message;
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die; 
Added: It seems that I found the focus of the problem, there is a javascript to display the email message successfully sent, and when I take it off, the email sends normally, but does not appear the message that the email was sent, directs to a page that prints the array. I would like to keep as it was, but that the data be sent to the POST
//Ajax contact
var form = $('.contact-form');
form.submit(function () {
    $this = $(this);
    $.post($(this).attr('action'), function(data) {
        $this.prev().text(data.message).fadeIn().delay(3000).fadeOut();
    },'json');
    return false;
});
Of the one
print_r($_POST); die('...');in the first line ofsedmail.phpand see what appears.– henriquedpereira
Nothing appears, comes empty.
– Felipe Santos
Nothing appears or returns an empty array?
– Papa Charlie
Nothing appears. I put to print the $_POST in the div where it shows the success message in HTML, and also nothing appears.
– Felipe Santos
How do you know the email is sent? by
$status?, check the file name and action of a print_r on$_REQUEST.– rray
I get the email. But with the fields empty. I added more information, which seems to be the focus of the problem.
– Felipe Santos