-4

i am trying to send an email when you fill up the contact us form using boothstrap. i am getting an email but its empty email with no information is filled. please help me where i am getting wrong.

Here is my PHP.

<?
if(isset($_POST['sendemail'])) {     

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "contact.hanif@gmail.com";

$email_subject = "General Inquery";
$name = $_POST['name']; 
$email = $_POST['email']; 
$subject =$_POST['subject']; 
$message = $_POST['message'];      

function clean_string($string) {

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

}
$email_message .= "First Name: ".clean_string($name)."\n";    

$email_message .= "Email: ".clean_string($email_from)."\n";

$email_message .= "subject: ".clean_string($subject)."\n";

$email_message .= "message: ".clean_string($message)."\n";

$headers = 'From: '.$email_from."\r\n".

   'Reply-To: '.$email_from."\r\n" .

  'X-Mailer: PHP/' . phpversion();

   @mail($email_to, $email_subject, $email_message, $headers);  

?>

The HTML:

<section id="contact-page">
    <div class="container">
        <div class="center">        
            <h2>Drop Your Message</h2>
            <p class="lead">Please feel free to contact us if you have any query.</p>
        </div> 
        <div class="row contact-wrap"> 
            <div class="status alert alert-success" style="display: none"></div>
            <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="required">
                    </div>
                    <div class="form-group">
                        <label>Email *</label>
                        <input type="email" name="email" class="form-control" required="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="required">
                    </div>
                    <div class="form-group">
                        <label>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> 
        </div><!--/.row-->
    </div><!--/.container-->
</section><!--/#contact-page-->
PHPhil
  • 1,555
  • 13
  • 27
jismtu
  • 69
  • 2
  • 9

1 Answers1

0

I don't think, this is your full code, but what I can see you have never set $_POST['sendemail'] so if(isset($_POST['sendemail'])) { will never be true.

EDIT

Just see the code below, I made 3 comments.

<?php
// 1. -------------↓ Change sendemail to submit
if(isset($_POST['submit'])) {         

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "contact.hanif@gmail.com";

$email_subject = "General Inquery";
$name = $_POST['name']; 
$email = $_POST['email']; 
$subject =$_POST['subject']; 
$message = $_POST['message'];      

function clean_string($string) {

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

}

// 2. --↓  Add $email_message = '';
$email_message = '';    
$email_message .= "First Name: ".clean_string($name)."\n";

// 3. -------------------------------------↓   Change $email_from to $email     
$email_message .= "Email: ".clean_string($email)."\n";    
$email_message .= "subject: ".clean_string($subject)."\n";    
$email_message .= "message: ".clean_string($message)."\n";    
echo "message: " . $email_message . "<br>";
}

?>
PHPhil
  • 1,555
  • 13
  • 27
  • @jismtu Didn't really describe any changes, only pointed out one of the points where your code was failing. Edited my answer. – PHPhil Jul 22 '15 at 15:03
  • @jismtu Just telling us "undefined" is not really helpful. Atleast tell us which variable is undefinded. – PHPhil Jul 22 '15 at 15:13
  • @jismtu edited my answer, I pointed out 3 things you should change/add. Looking at your website isn't going to help . I can't see you php code there. – PHPhil Jul 22 '15 at 15:32
  • now is keep showing email is sending. – jismtu Jul 22 '15 at 15:50
  • @jismtu can't really help you, I can only look at the code you provided. – PHPhil Jul 22 '15 at 16:05
  • thanks to all some how i fix the issue now i am able to send emails. thanks again – jismtu Jul 23 '15 at 12:12