Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > มือใหม่หัดใช้ smtp gmail รบกวนสอบถามเกี่ยวกับการตั้งค่าหน่อยค่ะ



 

มือใหม่หัดใช้ smtp gmail รบกวนสอบถามเกี่ยวกับการตั้งค่าหน่อยค่ะ

 



Topic : 105194



โพสกระทู้ ( 26 )
บทความ ( 0 )



สถานะออฟไลน์




พอดีว่าทำระบบสมัครสมาชิกแล้วให้สมาชิกยืนยันผ่านอีเมล์น่ะค่ะ
ปัญหาอยู่ตรงที่ว่าตอนทดสอบที่ locahost ก็สามารถส่งอีเมล์จาก gmail ได้ปกติ
แต่พออัพขึ้น host จริง แล้วอีเมล์ไม่ยอมส่งให้น่ะค่ะ
ไม่ค่อยเก่งเรื่องโค้ดเลยไม่รู้จะแก้การตั้งค่าตรงไหน

ยังไงรบกวนพี่ๆช่วยแนะนำให้หน่อยว่าต้องแก้ตรงจุดไหนบ้าง

ตรงนี้คือโค้ดจาก class.smtp ค่ะ

Code
<?php
/**
 * Send messages using a local or remote SMTP server.
 * It supports TLS and SSL crypto.
 * @class Smtp
 * @author wooptoo, http://wooptoo.com
 * @license BSD
 */
class Smtp {
	public $server;
	public $port;
	public $crypto;
	public $user;
	public $pass;

	private $timeout = '45';
	private $localhost = 'localhost';
	private $nl = "\r\n";
	private $conn;

	/**
	 * Connect and Auth to server.
	 *
	 * @param string $server - remote server address or 'localhost'
	 * @param int $port
	 * @param string $crypto - can be null, ssl, tls
	 * @param string $user - optional for localhost server
	 * @param string $pass - optional for localhost server
	 */
	function __construct($server, $port, $crypto=null, $user=null, $pass=null) {
		$this->server = $server;
		$this->port = $port;
		$this->crypto = $crypto;
		$this->user = $user;
		$this->pass = $pass;

		$this->connect();
		$this->auth();
	}

	/**
	 * Connect to server.
	 */
	function connect() {
		$this->crypto = strtolower(trim($this->crypto));
		$this->server = strtolower(trim($this->server));

		if($this->crypto == 'ssl')
			$this->server = 'ssl://' . $this->server;
		$this->conn = fsockopen(
			$this->server, $this->port, $errno, $errstr, $this->timeout
		);
		fgets($this->conn);
		return;
	}

	/**
	 * Auth.
	 */
	function auth() {
		fputs($this->conn, 'HELO ' . $this->localhost . $this->nl);
		fgets($this->conn);
		if($this->crypto == 'tls') {
			fputs($this->conn, 'STARTTLS' . $this->nl);
			fgets($this->conn);
			stream_socket_enable_crypto(
				$this->conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT
			);
			fputs($this->conn, 'HELO ' . $this->localhost . $this->nl);
			fgets($this->conn);
		}
		if($this->server != 'localhost') {
			fputs($this->conn, 'AUTH LOGIN' . $this->nl);
			fgets($this->conn);
			fputs($this->conn, base64_encode($this->user) . $this->nl);
			fgets($this->conn);
			fputs($this->conn, base64_encode($this->pass) . $this->nl);
			fgets($this->conn);
		}
		return;
	}

	/**
	 * Send an email.
	 *
	 * @param string $from
	 * @param string $to
	 * @param string $subject
	 * @param string $message
	 * @param string $headers - optional
	 */
	function send($from, $to, $subject, $message) {
		$headers="MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=utf-8\r\n";

		fputs($this->conn, 'MAIL FROM: <'. $from .'>'. $this->nl);
		fgets($this->conn);
		fputs($this->conn, 'RCPT TO: <'. $to .'>'. $this->nl);
		fgets($this->conn);
		fputs($this->conn, 'DATA'. $this->nl);
		fgets($this->conn);
		fputs($this->conn,
			'From: '. $from .$this->nl.
			'To: '. $to .$this->nl.
			'Subject: '. $subject .$this->nl.
			$headers .$this->nl.
			$this->nl.
			$message . $this->nl.
			'.' .$this->nl
		);
		fgets($this->conn);
		return;
	}

	/**
	 * Quit and disconnect.
	 */
	function __destruct() {
		fputs($this->conn, 'QUIT' . $this->nl);
		fgets($this->conn);
		fclose($this->conn);
	}
}

?>


ส่วนอันนี้เป็นโค้ดอีกอัน

Code
//SMTP Config
$SmtpServer="smtp.gmail.com";
$SmtpPort="587"; //default
$SmtCrypto="tls";
$SmtpUser="[email protected]";
$SmtpPass="xxxxxxx";

$mail = new Smtp($SmtpServer, $SmtpPort, $SmtCrypto, $SmtpUser,$SmtpPass);
$from="[email protected]";
$recieve="$email";
$subject="อีเมล์ยืนยันการสมัครสมาชิก www.trathe-travel.com";
$message="กรุณายืนยันตัวบุคคล ด้วยการกดที่ลิ้งค์ด้านล่าง ผู้ใช้จะสามารถทำการเข้าสู่ระบบได้ http://localhost/TratHe/TratHi/activate.php?access_key=$access_key <br>
ขอบพระคุณค่ะ";
$mail->send($from,$recieve, $subject, $message);




Tag : PHP, MySQL, JavaScript, Web Service







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-01-29 03:55:38 By : iceziism View : 1763 Reply : 3
 

 

No. 1



โพสกระทู้ ( 2,249 )
บทความ ( 5 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook Hi5 Blogger

แนะนำให้ใช้ phpmailer นะครับ

php-send-email-smtp-gmail-account






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-29 08:22:03 By : Manussawin
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใช้ phpmailer สะดวกสุดแล้วครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-29 09:01:56 By : mr.win
 

 

No. 3



โพสกระทู้ ( 26 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากๆค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-29 20:39:22 By : iceziism
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มือใหม่หัดใช้ smtp gmail รบกวนสอบถามเกี่ยวกับการตั้งค่าหน่อยค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่