 |
|
นี่ Code ครับ
Code (PHP)
function authMail($from, $namefrom, $to, $nameto, $subject, $message)
{
/*?your configuration here?*/
$smtpServer = "mail........com";
$port = "25";
$timeout = "30";
$username = "[email protected]";
$password = ".......";
$localhost = "mail.........com";
$newLine = "\r\n";
$secure = 1;
/*?you shouldn't need to mod anything else */
//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected to: $smtpResponse";
}
//say HELO to our little friend
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse'] = "$smtpResponse";
//start a tls session if needed
if($secure)
{
fputs($smtpConnect, "STARTTLS". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['tlsresponse'] = "$smtpResponse";
//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
}
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";
//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";
//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";
//email from
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";
//email to
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";
//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";
//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
//$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";
// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}
$str_text .="<TABLE style=\"border-style: dotted; \">
<TR>
<TD><p class=\"leftd\"><img src=\"images/logo_ruffy.png\" width=\"150\" height=\"70\" style=\"padding-left:330px;\" ></p></TD>
</TR>
<TR>
<TD><p style=\"margin-left:10px; \">ยินดีต้อนรับคุณ ". $myDataa[0][1]. " </p></TD>
</TR>
<TR>
<TD><p style=\"margin-left:10px;\">รหัสผ่านของคุณคือ ". $myDataa[0][9]. " </p></TD>
</tr>
<TR>
<td>กรุณาคลิกที่ link เพื่อทำการยืนยันการสมัครสมาชิกครับ</td>
<TD>
<p style=\"margin-left:10px;\">$website"."/activate.php?usr=".session_id()."&uid=".$myDataa[0][member_id]."<br/></p></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>";
$mail = $myDataa[0][4]; // เอาค่ามาจาก Table นะครับ
$from = "[email protected]";
$namefrom = "RuffyGift";
$to = $mail;
$nameto = $mail;
$subject = "ยินดีต้อนรับ RuffyGift";
$message = $str_text;
authMail($from, $namefrom, $to, $nameto, $subject, $message);
|
ประวัติการแก้ไข 2012-04-23 14:54:40
 |
 |
 |
 |
Date :
2012-04-23 11:03:58 |
By :
zimmpooh |
|
 |
 |
 |
 |
|
|
 |