ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingform ส่งเมล์ไม่ไปเลยครับ แต่อัพบาง Host กลับส่งได้ปกติ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: form ส่งเมล์ไม่ไปเลยครับ แต่อัพบาง Host กลับส่งได้ปกติ  (อ่าน 874 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
kengzz
ก๊วนเสียว
*

พลังน้ำใจ: 9
ออฟไลน์ ออฟไลน์

กระทู้: 216



ดูรายละเอียด เว็บไซต์
« เมื่อ: 15 มิถุนายน 2016, 23:06:06 »

ตอนนี้มีปัญหาเกี่ยวกับ  Form ครับ ส่งเข้าเมล์ครับ
นี่คือ Code ที่ใช้ ใช้กับบาง Host ได้ บาง Host ก็ขึ้น Error ครับ
ผมพลาดตรงไหนรบกวนชี้แนะครับผม

ขอขอบคุณครับ : )
#ทีมดีไซน์ #ไม่ค่อยได้จับ Code


โค๊ด:
<?php
 

    session_cache_limiter
'nocache' );
    
header'Expires: ' gmdate'r') );
    
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>&nbsp; ไม่ได้ใส่ชื่อ.' );
        echo 
json_encode($result );
        die;
    } 

    if(empty(
$email)){

        
$result = array( 'response' => 'error''empty'=>'email''message'=>'<strong>Error!</strong>&nbsp;ไม่ได้กรอกอีเมล์.' );
        echo 
json_encode($result );
        die;
    } 
 if(empty($opp)){

        
$result = array( 'response' => 'error''empty'=>'email''message'=>'<strong>Error!</strong>&nbsp; ไม่ได้กรอกอาชีพ.' );
        echo 
json_encode($result );
        die;
    } 
 if(empty($phone)){

        
$result = array( 'response' => 'error''empty'=>'email''message'=>'<strong>Error!</strong>&nbsp; ไม่ได้ใส่เบอร์โทร.' );
        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_contentsdirname(__FILE__) . '/email-templates/'.$email_template);

    
$contents =  strtr($templateContents$templateTags);

    if ( 
mail$to$subject$contents$headers ) ) {
        
$result = array( 'response' => 'success''message'=>'<strong>ขอบคุณครับ</strong>&nbsp;  <br><img src="assets/images/logo.png" width="100" height="61">.' );
    } else {
        
$result = array( 'response' => 'error''message'=>'<strong>Error!</strong>&nbsp; Can\'t Send Mail.'  );
    }

    echo 
json_encode$result );

    die;
« แก้ไขครั้งสุดท้าย: 15 มิถุนายน 2016, 23:06:50 โดย kengzz » บันทึกการเข้า
rapiz
Newbie
*

พลังน้ำใจ: 13
ออฟไลน์ ออฟไลน์

กระทู้: 81



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 15 มิถุนายน 2016, 23:30:17 »

น่าจะเป็นที่ ISP ของ Hosting ที่คุณใช่งานไม่มี Relay SMTP นะครับ ในกรณีแนะนำ PHPMailer ครับ (ใช้ SMTP Server ของ GMAIL)

ลองเชคว่า IP ติด Blacklist อยู่รึป่าวที่ลิ้งนี้ http://mxtoolbox.com/blacklists.aspx

ฝากโฮสลายเซ็นด้วยคับ
« แก้ไขครั้งสุดท้าย: 15 มิถุนายน 2016, 23:32:39 โดย rapiz » บันทึกการเข้า

Web Hosting,Reseller Hosting ราคาถูกเริ่มต้นแค่ 200฿ ต่อปีเท่านั้น!
VPS Linux, Windows (*ฟรี Direct Admin*) เริ่มต้นแค่ 700฿ ต่อเดือนเท่านั้น
รับเขียน Application บน Windows, Linux ด้วยทีมงานมืออาชีพ!!
สนใจ สมัครบริการด้านบน http://www.rapizhost.com
ติดต่อ 091-7733660 (24ชม.) Line ID : @rapizhost
kengzz
ก๊วนเสียว
*

พลังน้ำใจ: 9
ออฟไลน์ ออฟไลน์

กระทู้: 216



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 15 มิถุนายน 2016, 23:36:28 »

น่าจะเป็นที่ ISP ของ Hosting ที่คุณใช่งานไม่มี Relay SMTP นะครับ ในกรณีแนะนำ PHPMailer ครับ (ใช้ SMTP Server ของ GMAIL)

ลองเชคว่า IP ติด Blacklist อยู่รึป่าวที่ลิ้งนี้ http://mxtoolbox.com/blacklists.aspx

ฝากโฮสลายเซ็นด้วยคับ

ได้ครับผม เดี๋ยวผมลอง PHPMailer ดูนะครับผม
ได้ผลอย่างไรจะมาบอกครับผม

ขอบคุณมากนะครับผม

ปล.ตอนเย็น ๆ ผมเทส ๆ อัพโหลดขึ้นไปก็ส่งได้ปกติ สักพักอ้าวส่งไม่ได้ Error เลยครับ T T
บันทึกการเข้า
kengzz
ก๊วนเสียว
*

พลังน้ำใจ: 9
ออฟไลน์ ออฟไลน์

กระทู้: 216



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 16 มิถุนายน 2016, 09:07:48 »

ตอนนี้ทำได้แล้วนะครับผม
ขอบคุณมากครับ ใช้ PHP Mailer ตามที่บอกครับผม : )



ใช้ Code ดังนี้ครับ

โค๊ด:
<?php

$name 
$_REQUEST['name'] ;
$email $_REQUEST['email'] ;
$phone $_REQUEST['phone'] ;
$opp $_REQUEST['opp'] ;
$income $_REQUEST['income'] ;

require_once 
'PHPMailerAutoload.php';

$results_messages = array();

$mail = new PHPMailer(true);
$mail->CharSet 'utf-8';

class 
phpmailerAppException extends phpmailerException {}

try {
$to '[email protected]';
if(!
PHPMailer::validateAddress($to)) {
  throw new 
phpmailerAppException("Email address " $to " is invalid -- aborting!");
}
$mail->isSMTP();
$mail->SMTPDebug  1;
$mail->Host       "mail.host.com";
$mail->Port       "25";
$mail->SMTPSecure "none";
$mail->SMTPAuth   true;
$mail->Username   "[email protected]";
$mail->Password   "password";
$mail->addReplyTo("[email protected]""Best-Be");
$mail->From       "[email protected]";
$mail->FromName   "Best-Be";
$mail->addAddress("[email protected]""Keng");
$mail->IsHTML(true); 
$mail->Subject  strip_tags($_POST['name']. ",  ชื่อเรื่อง ");
$body = <<<'EOT'

EOT;
$subject    strip_tags($_POST['name']. ",  ชื่อเรื่อง");
    
$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();
$mail->Body "
    <html>
    <h2><b>ชื่อ : "
.$name.",<br> อีเมล์ : ".$email.", <br>โทร : ".$phone.", <br>อาชีพ : ".$opp.",<br>รายได้ต่อเดือน : ".$income."</b></h2>
    </html>"
;

try {
  
$mail->send();
  
$results_messages[] = "Message has been sent using SMTP";
  
header('Location: thankyou.html');
}
catch (
phpmailerException $e) {
  throw new 
phpmailerAppException('Unable to send to: ' $to': '.$e->getMessage());
}
}
catch (
phpmailerAppException $e) {
  
$results_messages[] = $e->errorMessage();
}

if (
count($results_messages) > 0) {
  echo 
"
Run results

\n"
;
  echo 
"
\n"
;
foreach (
$results_messages as $result) {
  echo 
"
$result
\n"
;
}
echo 
"
\n"
;
}
?>
« แก้ไขครั้งสุดท้าย: 16 มิถุนายน 2016, 09:08:33 โดย kengzz » บันทึกการเข้า
rapiz
Newbie
*

พลังน้ำใจ: 13
ออฟไลน์ ออฟไลน์

กระทู้: 81



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 16 มิถุนายน 2016, 12:43:10 »

ตอนนี้ทำได้แล้วนะครับผม
ขอบคุณมากครับ ใช้ PHP Mailer ตามที่บอกครับผม : )



ใช้ Code ดังนี้ครับ

โค๊ด:
<?php

$name 
$_REQUEST['name'] ;
$email $_REQUEST['email'] ;
$phone $_REQUEST['phone'] ;
$opp $_REQUEST['opp'] ;
$income $_REQUEST['income'] ;

require_once 
'PHPMailerAutoload.php';

$results_messages = array();

$mail = new PHPMailer(true);
$mail->CharSet 'utf-8';

class 
phpmailerAppException extends phpmailerException {}

try {
$to '[email protected]';
if(!
PHPMailer::validateAddress($to)) {
  throw new 
phpmailerAppException("Email address " $to " is invalid -- aborting!");
}
$mail->isSMTP();
$mail->SMTPDebug  1;
$mail->Host       "mail.host.com";
$mail->Port       "25";
$mail->SMTPSecure "none";
$mail->SMTPAuth   true;
$mail->Username   "[email protected]";
$mail->Password   "password";
$mail->addReplyTo("[email protected]""Best-Be");
$mail->From       "[email protected]";
$mail->FromName   "Best-Be";
$mail->addAddress("[email protected]""Keng");
$mail->IsHTML(true); 
$mail->Subject  strip_tags($_POST['name']. ",  ชื่อเรื่อง ");
$body = <<<'EOT'

EOT;
$subject    strip_tags($_POST['name']. ",  ชื่อเรื่อง");
    
$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();
$mail->Body "
    <html>
    <h2><b>ชื่อ : "
.$name.",<br> อีเมล์ : ".$email.", <br>โทร : ".$phone.", <br>อาชีพ : ".$opp.",<br>รายได้ต่อเดือน : ".$income."</b></h2>
    </html>"
;

try {
  
$mail->send();
  
$results_messages[] = "Message has been sent using SMTP";
  
header('Location: thankyou.html');
}
catch (
phpmailerException $e) {
  throw new 
phpmailerAppException('Unable to send to: ' $to': '.$e->getMessage());
}
}
catch (
phpmailerAppException $e) {
  
$results_messages[] = $e->errorMessage();
}

if (
count($results_messages) > 0) {
  echo 
"
Run results

\n"
;
  echo 
"
\n"
;
foreach (
$results_messages as $result) {
  echo 
"
$result
\n"
;
}
echo 
"
\n"
;
}
?>

 wanwan011
บันทึกการเข้า

Web Hosting,Reseller Hosting ราคาถูกเริ่มต้นแค่ 200฿ ต่อปีเท่านั้น!
VPS Linux, Windows (*ฟรี Direct Admin*) เริ่มต้นแค่ 700฿ ต่อเดือนเท่านั้น
รับเขียน Application บน Windows, Linux ด้วยทีมงานมืออาชีพ!!
สนใจ สมัครบริการด้านบน http://www.rapizhost.com
ติดต่อ 091-7733660 (24ชม.) Line ID : @rapizhost
หน้า: [1]   ขึ้นบน
พิมพ์