หน้าเว็บ

วันอังคารที่ 12 เมษายน พ.ศ. 2554

วันจันทร์ที่ 11 เมษายน พ.ศ. 2554

การส่งเมล์ ของ PHP โดยใช้ PHPMailer

Download PHPMailer จากที่นี้
ขั้นตอนการใช้งาน PHPMailer หรือ วิธีการส่งเมล์จาก php ด้วย PHPMailer
1. ทำการแตกไฟล์ PHPMailer_v5.1.zip ที่ได้จากการ download มา จากนั้น upload ขึ้นไปไว้บน server ใน directory public_html
2. ทดลองส่งเมล์ของ gmail ก็ได้นะค่ะ โดยเข้า PHPMailer_v5.1\examples\test_smtp_gmail_basic.php  จากนั้นทำตามนี้ได้เลยค่ะ


<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();
$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "your@gmail.com";  // GMAIL username
$mail->Password   = "xxxx";            // GMAIL password
$mail->SetFrom(your@gmail.com', 'First Last');
$mail->AddReplyTo("mailto:your@gmail.com%22,%22First Last");
$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "whoto@gmail.com";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>
</body>
</html>
3. เวลาเรียกใช้งาน ให้ใช้ smtpmail("อีเมล์ปลายทาง","หัวข้อส่ง email","ข้อความที่เราต้องการส่ง");
4. ข้อนี้สำคัญค่ะ แก้  php.ini ของคุณด้วยนะค่ะ  ;extension=php_openssl.dll  เป็น  extension=php_openssl.dll


เพียงเท่านี้ก็ส่งเมล์ได้แล้วค่ะ

วันเสาร์ที่ 9 เมษายน พ.ศ. 2554

แก้ไขปัญหาเรื่อง CentOs5 ฐานข้อมูล oracle ไม่อ่านภาษาไทย

หลายๆคนที่เคยเจอปัญหาเรื่องภาษาไทยกับฐานข้อมูล oracle ซึ่งเราก็เป็นหนึ่งในนั้น เราเลยลองไปหาข้อมูลมา แล้วลองนำไปทำดู ปรากฎว่าใช้งานได้ เราเลยนำมาแบ่งปันให้เพื่อนๆ ลองเอาไปใช้กันนะจ๊ะ ลืมบอกไปว่า เราลองกับเครื่อง CenOs5 apache ของเรา เป็น xmapp นะจ๊ะ

   /opt/lampp/bin/envvars 
     เพิ่ม  export NLS_LANG=THAI_THAILAND.TH8TISASCII

ถ้าไม่หายลองไปดูที่ฐานข้อมูลของเราก่อนว่า NLS ของเราเป็นอะไร ลองทำตามนี้ http://www.oracleskill.com/oracle-tutorials/display-nls-thai.html เลยนะจ๊ะ

วันอังคารที่ 5 เมษายน พ.ศ. 2554

เทคนิคเล็กๆน้อยในการ Vhost บน window

Vhost คือ อะไร ? คำถามนี้หลายคนอาจจะได้ยินมา Vhost ย่อมาจาก Virtual host หรือ การจำลองชื่อ Host เป็นเพียง ชื่อเสมือน หรือ ชื่อหลอกๆ ไว้ใช้งาน ซึ่งไม่ได้มี Host นี้อยู่จริง Vhost นี้จะมีประโยชน์ในการปิดบัง IP-address จริง
วิธี set ก็ไม่อยากเลยค่ะ ก่อนอื่นเครื่อง window ของคุณต้อง ติดตั้ง apache เรียบร้อยแล้วก่อน เมื่อเรียบร้อยแล้วก็มาเริ่มกันเลยนะค่ะ 

 1. PATH_APACHE(ของคุณ)/apache/conf/httpd/extra/httpd-vhosts
   จากPATH_APACHE(ของคุณ)/apache/conf/httpd/extra/httpd-vhostsนั้นเพิ่ม

 <VirtualHost *:80>
    ServerAdmin   // ชื่อ urlที่ต้องการ
    DocumentRoot D:/xampp/htdocs/truelifedaily  // เป็น pathที่คุณต้องการ
    ServerName app2u  

    ServerAlias app2u
 </VirtualHost>
เมื่อเรียบแก้ไขเรียบร้อยแล้วบันทึกค่ะ (ถ้าต้องการเพิ่มหลายๆ vhost ให้เพิ่มชุดนี้ตามที่ต้องการนะค่ะ )


2. PATH_APACHE(ของคุณ)/apache/conf/httpd/extra/httpd-vhosts
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf 


แก้ไขเป็น

# Virtual hosts
Include conf/extra/httpd-vhosts.conf


อันนี้เป็นการเรียกอ่านไฟล์ vhost ที่เราเพิ่มเข้าไปจากข้อ 1 (แก้ไขเพียงการเพิ่ม vhost เป็นครั้งแรกเท่านั้นค่ะ  )
3. map vhost เพื่อให้เครื่องของเราอ่าน Vhost ที่เรา set ไว้ค่ะ
    C:\Windows\System32\drivers\etc\host 
เพิ่ม
127.0.0.1     app2u
4. จากนั้น restart apache พร้อมทั้ง ปิด browser ที่เปิดอยู่ให้หมด ด้วยนะค่ะ
เท่านั้นก็สามารถ run Vhost ได้แล้วค่ะ
แล้วไว้ติดตามการตั้งค่า Vhost ของ linux ในโอกาสหน้านะค่ะ
 ......................... nooneung ....................