|
 |
|
มือใหม่หัดใช้ smtp gmail รบกวนสอบถามเกี่ยวกับการตั้งค่าหน่อยค่ะ |
|
 |
|
|
 |
 |
|
พอดีว่าทำระบบสมัครสมาชิกแล้วให้สมาชิกยืนยันผ่านอีเมล์น่ะค่ะ
ปัญหาอยู่ตรงที่ว่าตอนทดสอบที่ 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

|
|
 |
 |
 |
 |
Date :
2014-01-29 03:55:38 |
By :
iceziism |
View :
1821 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ phpmailer สะดวกสุดแล้วครับ
|
 |
 |
 |
 |
Date :
2014-01-29 09:01:56 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆค่ะ
|
 |
 |
 |
 |
Date :
2014-01-29 20:39:22 |
By :
iceziism |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|