001.
function
authMail(
$from
,
$namefrom
,
$to
,
$nameto
,
$subject
,
$message
)
002.
{
003.
004.
$smtpServer
=
"mail........com"
;
005.
$port
=
"25"
;
006.
$timeout
=
"30"
;
007.
$username
=
"info@.......com"
;
008.
$password
=
"......."
;
009.
$localhost
=
"mail.........com"
;
010.
$newLine
=
"\r\n"
;
011.
$secure
= 1;
012.
013.
014.
015.
$smtpConnect
=
fsockopen
(
$smtpServer
,
$port
,
$errno
,
$errstr
,
$timeout
);
016.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
017.
if
(
empty
(
$smtpConnect
))
018.
{
019.
$output
=
"Failed to connect: $smtpResponse"
;
020.
return
$output
;
021.
}
022.
else
023.
{
024.
$logArray
[
'connection'
] =
"Connected to: $smtpResponse"
;
025.
}
026.
027.
028.
fputs
(
$smtpConnect
,
"HELO $localhost"
.
$newLine
);
029.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
030.
$logArray
[
'heloresponse'
] =
"$smtpResponse"
;
031.
032.
033.
if
(
$secure
)
034.
{
035.
fputs
(
$smtpConnect
,
"STARTTLS"
.
$newLine
);
036.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
037.
$logArray
[
'tlsresponse'
] =
"$smtpResponse"
;
038.
039.
040.
fputs
(
$smtpConnect
,
"HELO $localhost"
.
$newLine
);
041.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
042.
$logArray
[
'heloresponse2'
] =
"$smtpResponse"
;
043.
}
044.
045.
046.
fputs
(
$smtpConnect
,
"AUTH LOGIN"
.
$newLine
);
047.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
048.
$logArray
[
'authrequest'
] =
"$smtpResponse"
;
049.
050.
051.
fputs
(
$smtpConnect
,
base64_encode
(
$username
) .
$newLine
);
052.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
053.
$logArray
[
'authusername'
] =
"$smtpResponse"
;
054.
055.
056.
fputs
(
$smtpConnect
,
base64_encode
(
$password
) .
$newLine
);
057.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
058.
$logArray
[
'authpassword'
] =
"$smtpResponse"
;
059.
060.
061.
fputs
(
$smtpConnect
,
"MAIL FROM: $from"
.
$newLine
);
062.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
063.
$logArray
[
'mailfromresponse'
] =
"$smtpResponse"
;
064.
065.
066.
fputs
(
$smtpConnect
,
"RCPT TO: $to"
.
$newLine
);
067.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
068.
$logArray
[
'mailtoresponse'
] =
"$smtpResponse"
;
069.
070.
071.
fputs
(
$smtpConnect
,
"DATA"
.
$newLine
);
072.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
073.
$logArray
[
'data1response'
] =
"$smtpResponse"
;
074.
075.
076.
$headers
=
"MIME-Version: 1.0"
.
$newLine
;
077.
078.
$headers
.=
"To: $nameto <$to>"
.
$newLine
;
079.
$headers
.=
"From: $namefrom <$from>"
.
$newLine
;
080.
081.
082.
fputs
(
$smtpConnect
,
"To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n"
);
083.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
084.
$logArray
[
'data2response'
] =
"$smtpResponse"
;
085.
086.
087.
fputs
(
$smtpConnect
,
"QUIT"
.
$newLine
);
088.
$smtpResponse
=
fgets
(
$smtpConnect
, 4096);
089.
$logArray
[
'quitresponse'
] =
"$smtpResponse"
;
090.
$logArray
[
'quitcode'
] =
substr
(
$smtpResponse
,0,3);
091.
fclose(
$smtpConnect
);
092.
093.
return
(
$logArray
);
094.
}
095.
096.
097.
098.
$str_text
.=
"<TABLE style=\"border-style: dotted; \"
>
099.
<TR>
100.
<TD><p
class
=\
"leftd\"><img src=\"images/logo_ruffy.png\" width=\"150\" height=\"70\" style=\"padding-left:330px;\"
></p></TD>
101.
</TR>
102.
<TR>
103.
<TD><p style=\
"margin-left:10px; \">ยินดีต้อนรับคุณ "
.
$myDataa
[0][1]. " </p></TD>
104.
</TR>
105.
<TR>
106.
<TD><p style=\
"margin-left:10px;\">รหัสผ่านของคุณคือ "
.
$myDataa
[0][9]. " </p></TD>
107.
</tr>
108.
<TR>
109.
<td>กรุณาคลิกที่ link เพื่อทำการยืนยันการสมัครสมาชิกครับ</td>
110.
<TD>
111.
<p style=\
"margin-left:10px;\">$website"
.
"/activate.php?usr="
.session_id().
"&uid="
.
$myDataa
[0][member_id]."<br/></p></TD>
112.
113.
</TR>
114.
<TR>
115.
<TD></TD>
116.
<TD></TD>
117.
<TD></TD>
118.
</TR>
119.
<TR>
120.
<TD></TD>
121.
<TD></TD>
122.
<TD></TD>
123.
</TR>
124.
</TABLE>";
125.
126.
$mail
=
$myDataa
[0][4];
127.
128.
$from
=
"no-reply@ruffygift.com"
;
129.
$namefrom
=
"RuffyGift"
;
130.
$to
=
$mail
;
131.
$nameto
=
$mail
;
132.
$subject
=
"ยินดีต้อนรับ RuffyGift"
;
133.
$message
=
$str_text
;
134.
authMail(
$from
,
$namefrom
,
$to
,
$nameto
,
$subject
,
$message
);