-3

I've been code my own web and currently stuck on making forms. I can't receive any email that I have input on my own website eventhought my php code is already Success. Here's my form code in HTML

<form action="booking-process.php" method="post">
        <div class="container fluid">
           <h2 class="midtext">Booking Service</h2>
           <h5 class="ff2 note">* Harap Melakukan Booking 1 hari sebelumnya.</h5>
            <div class="col-md-4 col-xs-12 col-sm-6">
                <label for="nama">Nama</label>
                <input type="text" name="nama" class="form-control">

                <label for="telp">Telepon/HP</label>
                <input type="text" name="telp" class="form-control">
            </div>
            <div class="col-md-4 col-xs-12 col-sm-6">
                <label for="plat">Nomor Polisi/Plat</label>
                <input type="text" name="plat" class="form-control">

                <label for="jam">Jam</label>
                <input type="text" name="jam" class="form-control" placeholder="HH:MM">
            </div>
            <div class="col-md-4 col-xs-12 col-sm-6">
                <label for="tanggal">Tanggal</label>
                <input type="text" name="tanggal" class="form-control" placeholder="DD/MM/YYYY">

                <label for="jenis" class="bookingdate">Jenis</label> <br>
                <select name="jenis" id="jenis" class="form-control">
                    <option value="BookingShowroom">Booking Showroom</option>
                    <option value="ToyotaHomeService">Toyota Home Service</option>
                </select>
            </div>
        </div>
        <div class="col-md-12">
            <button type="submit" class="mybtn ff2">BOOK</button>
        </div>
    </form>

and here's my php code

<?php

$to = "elmokun17@gmail.com";
$nama = $_REQUEST['nama'];
$telp = $_REQUEST['telp'];
$plat = $_REQUEST['plat'];
$jam = $_REQUEST['jam'];
$tanggal = $_REQUEST['tanggal'];
$jenis = $_REQUEST['jenis'];
$headers = "From: $from";

$fields = array();
$fields{"nama"} = $nama;
$fields{"telp"} = $telp;
$fields{"plat"} = $plat;
$fields{"jam"} = $jam;
$fields{"tanggal"} = $tanggal;
$fields{"jenis"} = $jenis;

$body = "FORM BOOKING\n\n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$send = mail($to, $subject, $body, $headers);
echo 'SUCCESS'
?>
mega6382
  • 9,211
  • 17
  • 48
  • 69
  • I did not see assigned value for $subject. – wishab Nov 14 '17 at 09:42
  • 1
    Echo-ing "SUCCESS" after a function doesn't mean the function works properly. Have you tried debugging it as described in questions like: https://stackoverflow.com/questions/7912992/php-mail-does-not-get-sent-how-do-i-debug (or any related)? – Edwin Nov 14 '17 at 09:43
  • Echoing success doesn't necessarily means mail() execute successfully. Try put some subject "subject" – wishab Nov 14 '17 at 09:45
  • @Harvin Khong Check your Spam Folder. Mails Working fine and Improve your Mail Format. – Raghav Nov 14 '17 at 09:48
  • The posted code contains multiple security vulnerabilities. – CubicleSoft Nov 15 '17 at 15:28

2 Answers2

0

Just echo Success at the end of the file, does not mean it is working fine. You need to check whether is it working or not, use if else to verify this -

if ($send) {
echo "mail send ... OK"; 
} else {
echo "mail send ... ERROR!";

}

Also you need to send more hearders to get it proper work like Content-Type, MIME-Version, Reply-To etc.

Refer this Link it has details.

Param Kumar
  • 123
  • 3
  • 18
-1
    <?php

    $to = "elmokun17@gmail.com";
    $nama = $_REQUEST['nama'];
    $telp = $_REQUEST['telp'];
    $plat = $_REQUEST['plat'];
    $jam = $_REQUEST['jam'];
    $tanggal = $_REQUEST['tanggal'];
    $jenis = $_REQUEST['jenis'];
    /*$headers = "From: $from";*/

    $fields = array();
    $fields{"nama"} = $nama;
    $fields{"telp"} = $telp;
    $fields{"plat"} = $plat;
    $fields{"jam"} = $jam;
    $fields{"tanggal"} = $tanggal;
    $fields{"jenis"} = $jenis;

    $subject = "Testing";
    $body = "FORM BOOKING\n\n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

    $headers = "MIME-Version: 1.0" . "\n";
    $headers .= "Content-type: text/html; charset=utf-8" . "\n";
    $headers .= "From: $from" . "\n";

    if( mail($to, $subject, $body, $headers) )
    echo 'SUCCESS';
    else
    echo 'FAILURE';

    ?>