-1

I'm having contact form in my website, when user filled the form it should send the form with user content to my mail. I have tried this it show blank page.

Here is my form:

<form id="contact_form" action="mail.php" method="post" class="form-horizontal">
    <div class="form-group">
        <label class="col-md-3 control-label">Name:</label>
        <div class="col-md-5">
            <input type="email" class="form-control" name="name" />
        </div>
     </div>
     <div class="form-group">
         <label class="col-md-3 control-label">E-mail:</label>
         <div class="col-md-5">
             <input type="email" class="form-control" name="email" />
         </div>
     </div>
     <div class="form-group">
         <label class="col-md-3 control-label">Mobile Number:</label>
         <div class="col-md-5">
             <input type="email" class="form-control" name="mob" />
         </div>
     </div>
     <div class="form-group">
         <label class="col-md-3 control-label">Requirement</label>
         <div class="col-md-5">
             <textarea class="form-control" name="mess" cols="30" rows="10" placeholder="Your Message"></textarea>
         </div>
     </div>
     <div class="form-group">
         <div class="col-md-5 col-md-offset-3">
             <button type="submit" class="btn btn-default">GET A QUOTE</button>
          </div>
    </div>
</form>

And PHP mailer: I have tried this, when executed it shown blank

<?php 
if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $mob = $_POST['mob'];
    $mess = $_POST['mess'];
    $subject = 'Message from website';
    $to = 'mailus@pebibytetech.in';
    $headers="From: {$email}\r\nReply-To: {$email}";
    mail($to,$subject,$message,$headers);
    $success = "Thank you! You're email has been sent.";
}
?>
Alexis Tyler
  • 1,394
  • 6
  • 30
  • 48

4 Answers4

1

PHPSimpleMail

Simple PHP Mailer is Better then inbuilt PHP Function. look at this link for more info.

Also you need to use input type according to your need. like if you want to get Email then use

For Email: <input type="email" name="email">
For Phone: <input type="tel" name="phonenumber">
For name: <input type="text" name="FirstName">

Don't use email type in all input fields.

Sahil Patel
  • 1,570
  • 2
  • 15
  • 34
0

You are not displaying anything while the mail() is success.

   if(mail($to,$subject,$message,$headers))
         echo $success = "Thank you! You're email has been sent.";
    else
         echo "Failed!!";

Also you have not defined $message. Change $mess to $message.

Abey
  • 1,408
  • 11
  • 26
0

I think you missing enctype="multipart/form-data" form attribute. Study below link. It is very useful. Contact Form Data Email Link

Maulik M. Dodia
  • 95
  • 3
  • 14
0

In your Form(Replace this to your code)

<form action="#" method="post" class="form-horizontal">
    <div class="form-group">
        <label class="col-md-3 control-label">Name:</label>
        <div class="col-md-5">
            <input type="text" class="form-control" name="name" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-3 control-label">E-mail:</label>
        <div class="col-md-5">
            <input type="email" class="form-control" name="email" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-3 control-label">Mobile Number:</label>
        <div class="col-md-5">
            <input type="number" class="form-control" name="mob" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-3 control-label">Requirement</label>
        <div class="col-md-5">
            <textarea class="form-control" name="mess" cols="30" rows="10" placeholder="Your Message"></textarea>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-5 col-md-offset-3">
            <input type="submit" name="submit" class="btn btn-default" value="GET A QUOTE">
        </div>
    </div>
</form>

then below the form, add this php code

<?php
    if(isset($_POST['submit']))
    {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $mob = $_POST['mob'];
        $mess = $_POST['mess'];

        if(empty($name)||empty($email)||empty($mob))
        {
            ?>
            <script>
                alert('Name, Email, Mobile is empty');
            </script>
        <?php
        }
        else
        {
            // Method 01 (Normal method)
            $to = 'mailus@pebibytetech.in';
            $subject = 'Message from website';

            $headers="From:".$email;

            $message = 'Customer Name :'.$name;
            $message .= '<br>Customer Mobile :'.$mob;
            $message .= '<br>Customer Email :'.$email;
            $message .= '<br>Customer Message :'.$mess;

            $mail = mail($to,$subject,$message,$headers);
            if(isset($mail))
            {
                ?>
                <script>
                    alert('Mail Sent');
                </script>
            <?php
            }
            else
            {

                ?>
                <script>
                    alert('Mail Sending Failed');
                </script>
            <?php
            }

            //method 02, Using table

            $to = 'mailus@pebibytetech.in';
            $subject = 'Message from website';

            $headers="From:".$email;

            $message = '<html><body>';
            $message .= '<table rules="all" style="border: 1px solid #eee; width: 850px" cellpadding="10">';
            $message .= "<tr><td width='25%'><strong>Name</strong> </td><td width='75%'>".strip_tags($_POST['name'])."</td></tr>";
            $message .= "<tr><td><strong>Email</strong> </td><td>" .strip_tags($_POST['email']) . "</td></tr>";
            $message .= "<tr><td><strong>Mobile</strong> </td><td>" .strip_tags($_POST['mob']) . "</td></tr>";
            $message .= "<tr><td><strong>Message</strong> </td><td>" . strip_tags($_POST['mess']). "</td></tr>";
            $message .= "</table>";
            $message .= "</body></html>";

            $headers = "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
            $headers .="From:".$email;//can add  $headers="Cc:".$email;

            $mail = mail($to,$subject,$message,$headers);

            if(isset($mail))
            {
                ?>
                <script>
                    alert('Mail Sent');
                </script>
            <?php
            }
            else
            {

                ?>
                <script>
                    alert('Mail Sending Failed');
                </script>
            <?php
            }
        }
    }
?>
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85