Page 1 of 1

Why php script not picking up data from contact form?

Posted: Wed Jun 17, 2015 6:08 am
by ajay72
I have created contact form in my website & i use php code. Send mail is working but in the mail i didn't see the data from form which is entered in name, email & massage box.

Please check the below added php code & form

Code: Select all

<?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 = 'email@email.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;
form:

Code: Select all

<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 for="name">Name *</label>
<input type="text" id="name" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label for="email">Email *</label>
<input type="email" id="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label for="phone">Phone</label>
<input type="number" name="phone" class="form-control">
</div>
<div class="form-group">
<label for="company_name">Company Name</label>
<input type="text" name="company_name" class="form-control">
</div> 
</div>
<div class="col-sm-5">
<div class="form-group">
<label for="subject">Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label for="massage">Message *</label>
<textarea name="message" id="message" required="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>
Please help me.....

Re: Why php script not picking up data from contact form?

Posted: Wed Jun 17, 2015 9:21 am
by Christopher
Take out the error suppression to see if there are errors/warnings. You should instead do isset() checks.