หัวข้อ: ช่วยดูโค๊ดส่งเมลหน่อยคะ รายละเอียดมันไม่เข้า
เริ่มหัวข้อโดย: icenobu ที่ 15 พฤษภาคม 2018, 15:19:15
กำลังทำฟอร์มส่งข้อมูลคะส่งเมลได้แล้ว แต่พวกรายละเอียดมันไม่มีข้อมูล มีแต่ข้อมูลหัวข้อเมล ทำมาหลายวันแล้วไม่ได้สักที <?php if($_POST) { require('constant.php'); $user_name = filter_var($_POST["name"], FILTER_SANITIZE_STRING); $user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL); $subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING); $user_phone = filter_var($_POST["phone"], FILTER_SANITIZE_STRING); $content = filter_var($_POST["content"], FILTER_SANITIZE_STRING); if(empty($user_name)) { $empty[] = "<b>Name</b>"; } if(empty($user_email)) { $empty[] = "<b>Email</b>"; } if(empty($user_phone)) { $empty[] = "<b>Phone Number</b>"; } if(empty($subject)) { $empty[] = "<b>Subject</b>"; } if(empty($content)) { $empty[] = "<b>Comments</b>"; } if(!empty($empty)) { $output = json_encode(array('type'=>'error', 'text' => implode(", ",$empty) . ' Required!')); die($output); } if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation $output = json_encode(array('type'=>'error', 'text' => '<b>'.$user_email.'</b> is an invalid Email, please correct it.')); die($output); } //reCAPTCHA validation if (isset($_POST['g-recaptcha-response'])) { require('component/recaptcha/src/autoload.php'); $recaptcha = new \ReCaptcha\ReCaptcha(SECRET_KEY, new \ReCaptcha\RequestMethod\SocketPost());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) { $output = json_encode(array('type'=>'error', 'text' => '<b>Captcha</b> Validation Required!')); die($output); } } $toEmail = "[email protected]"; $mailHeaders = "From: " . $user_name . "<" . $user_email . ">\r\n"; if (mail($toEmail, "Contact Mail", $content, $mailHeaders)) { $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .', thank you for the comments. We will get back to you shortly.')); die($output); } else { $output = json_encode(array('type'=>'error', 'text' => 'Unable to send email, please contact'.SENDER_EMAIL)); die($output); } } ?>
หัวข้อ: Re: ช่วยดูโค๊ดส่งเมลหน่อยคะ รายละเอียดมันไม่เข้า
เริ่มหัวข้อโดย: aommiez ที่ 15 พฤษภาคม 2018, 15:59:34
ลอง composer ตัว phpmailer มาใช้ดูครับ น่าจะง่ายขึ้น
หัวข้อ: Re: ช่วยดูโค๊ดส่งเมลหน่อยคะ รายละเอียดมันไม่เข้า
เริ่มหัวข้อโดย: Nuxsell.com ที่ 15 พฤษภาคม 2018, 18:40:03
// Always set content-type when sending HTML email $mailHeaders = "MIME-Version: 1.0" . "\r\n"; $mailHeaders .= "Content-type:text/html;charset=UTF-8" . "\r\n";
หัวข้อ: Re: ช่วยดูโค๊ดส่งเมลหน่อยคะ รายละเอียดมันไม่เข้า
เริ่มหัวข้อโดย: icenobu ที่ 15 พฤษภาคม 2018, 19:39:27
ขอบคุณมากน่ะค่ะ ทุกท่าน ทำได้แล้วค่ะ :wanwan017:
|