ตอนนี้มีปัญหาเกี่ยวกับ Form ครับ ส่งเข้าเมล์ครับ
นี่คือ Code ที่ใช้ ใช้กับบาง Host ได้ บาง Host ก็ขึ้น Error ครับ
ผมพลาดตรงไหนรบกวนชี้แนะครับผม
ขอขอบคุณครับ : )
#ทีมดีไซน์ #ไม่ค่อยได้จับ Code
<?php
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$to = '[email protected]';
$email_template = 'simple.html';
$subject = strip_tags($_POST['name']. ", ต้องการรับบริการตรวจสุขภาพจาก Best-Be");
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$name = strip_tags($_POST['name']);
$opp = strip_tags($_POST['opp']);
$message = strip_tags($_POST['message']);
$income = trim($_POST['income']);
$result = array();
if(empty($name)){
$result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Error!</strong> ไม่ได้ใส่ชื่อ.' );
echo json_encode($result );
die;
}
if(empty($email)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> ไม่ได้กรอกอีเมล์.' );
echo json_encode($result );
die;
}
if(empty($opp)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> ไม่ได้กรอกอาชีพ.' );
echo json_encode($result );
die;
}
if(empty($phone)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> ไม่ได้ใส่เบอร์โทร.' );
echo json_encode($result );
die;
}
$headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templateTags = array(
'{{subject}}' => $subject,
'{{email}}'=>$email,
'{{message}}'=>$message,
'{{name}}'=>$name,
'{{opp}}'=>$opp,
'{{income}}'=>$income,
'{{phone}}'=>$phone
);
$templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$email_template);
$contents = strtr($templateContents, $templateTags);
if ( mail( $to, $subject, $contents, $headers ) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>ขอบคุณครับ</strong> <br><img src="assets/images/logo.png" width="100" height="61">.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Can\'t Send Mail.' );
}
echo json_encode( $result );
die;