我一直在编写自己的网络代码,目前仍在制作表单。我无法收到任何我在自己的网站上输入的电子邮件。我的PHP代码已经成功了。 这是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>
这是我的PHP代码
<?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'
?>
答案 0 :(得分:0)
只是在文件末尾回显成功,并不意味着它正常工作。您需要检查它是否正常工作,使用if else来验证这一点 -
if ($send) {
echo "mail send ... OK";
} else {
echo "mail send ... ERROR!";
}
此外,您还需要发送更多的听众才能正常工作,例如Content-Type,MIME-Version,Reply-To等。
请参阅此Link,其中包含详细信息。
答案 1 :(得分:-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';
?>