装了个UCHOME,设置一些参数的时候发现了个问题,怎么弄也不能发送邮件,比较郁闷,去discuz查了N多资料,也还是不行,按照上面设置的步骤来,还是不可以,比较头疼,大致原因好像是这样
环境:
Windows操作系统,IIS6.0做为php解释引擎
可能为windows原因,服务器又没有安装邮件系统,所以默认的发送方法不可行,也就是"通过 PHP 函数的 sendmail 发送(推荐此方式)",实验了N多次,不可以.
没有办法,只好自己看代码修改了,通过第二种方式,也就是"通过 SOCKET 连接 SMTP 服务器发送(支持 ESMTP 验证)",但是实验了几个邮箱,QQ的没有发送成功,gmail没有发送成功,但是foxmail发送成功了.这个时候有点知道了,按理说应该是服务器设置原因,gmail必须要安全验证,也就是ssl发送才可以,看了下UCHOME的邮件发送代码,发现挺简单,加一句话就可以了.
打开source/function_sendmail.php,查找fsockopen,然后修改这句为:
fsockopen("ssl://".$mail['server'], $mail['port'], $errno, $errstr, 30)
这样的话,就可以了,但是需要服务器支持OpenSSL,这个可以通过查看PHPINFO来确定是否支持,嘿嘿,本来偶的也不支持,但是联系了下陈哥,帮忙解决了.如何开启OpenSSL和mcrypt到此为止,OK了,Discuz论坛上一堆人文这个问题,但是没几个说怎么解决的,翻来覆去都是那么几个帖子,拜托,就那么几个选项还能不知道怎么填么,问题是根本没把问题描述清楚.- -#
PS:而且sendmail.php这个文件在官方的程序里面貌似还没有?至少我这个版本里面没有,不知道大C他们搞什么呢.下面是这个文件的代码,放到/source/cron/文件夹下面就可以了.
代码
1
<?
php
2
/*
3
[UCenter Home] (C) 2007-2008 Comsenz Inc.
4
$Id: sendmail.php 8302 2008-08-01 02:10:28Z liguode $
5
*/
6
if
(
!
defined
(
'
IN_UCHOME
'
)) {
7
exit
(
'
Access Denied
'
);
8
}
9
10
//
防止超时
11
set_time_limit
(
0
);
12
13
//
一次发送邮件个数
14
$pernum
=
5
;
15
16
include_once
(S_ROOT
.
'
./source/function_sendmail.php
'
);
17
18
//
获取发送队列
19
$emails
=
$touids
=
array
();
20
$query
=
$_SGLOBAL
[
'
db
'
]
->
query(
"
SELECT touid, email FROM
"
.
tname(
'
mailcron
'
)
.
"
WHERE sendtime<='
$_SGLOBAL
[timestamp]' ORDER BY sendtime LIMIT 0,
$pernum
"
);
21
while
(
$value
=
$_SGLOBAL
[
'
db
'
]
->
fetch_array(
$query
)) {
22
if
(
$value
[
'
email
'
]) {
23
$emails
[
$value
[
'
email
'
]]
=
$value
[
'
email
'
];
24
}
elseif
(
$value
[
'
touid
'
]) {
25
$touids
[
$value
[
'
touid
'
]]
=
$value
[
'
touid
'
];
26
}
27
}
28
29
//
获取用户邮件
30
$useremails
=
$deluids
=
array
();
31
if
(
$touids
) {
32
$query
=
$_SGLOBAL
[
'
db
'
]
->
query(
"
SELECT sf.emailcheck, sf.email, s.uid, s.lastsend, s.updatetime
33
FROM
"
.
tname(
'
space
'
)
.
"
s
34
LEFT JOIN
"
.
tname(
'
spacefield
'
)
.
"
sf ON sf.uid=s.uid
35
WHERE s.uid IN (
"
.
simplode(
$touids
)
.
"
)
"
);
36
while
(
$value
=
$_SGLOBAL
[
'
db
'
]
->
fetch_array(
$query
)) {
37
if
(
$_SCONFIG
[
'
sendmailday
'
]
&&
$value
[
'
emailcheck
'
]
&&
$value
[
'
email
'
]
&&
(
$_SGLOBAL
[
'
timestamp
'
]
-
$value
[
'
lastlogin
'
]
>
$_SCONFIG
[
'
sendmailday
'
]
*
86400
)) {
38
$useremails
[
$value
[
'
uid
'
]]
=
$value
[
'
email
'
];
39
}
else
{
40
$deluids
[
$value
[
'
uid
'
]]
=
$value
[
'
uid
'
];
41
unset
(
$touids
[
$value
[
'
uid
'
]]);
42
}
43
}
44
}
45
46
47
48
//
删除无效的用户邮件
49
if
(
$deluids
) {
50
$_SGLOBAL
[
'
db
'
]
->
query(
"
DELETE FROM
"
.
tname(
'
mailcron
'
)
.
"
WHERE touid IN (
"
.
simplode(
$deluids
)
.
"
)
"
);
51
$_SGLOBAL
[
'
db
'
]
->
query(
"
DELETE FROM
"
.
tname(
'
mailqueue
'
)
.
"
WHERE touid IN (
"
.
simplode(
$deluids
)
.
"
)
"
);
52
}
53
54
//
获取邮件队列
55
$wherearr
=
$sends
=
$sendmails
=
array
();
56
if
(
$emails
) {
57
$wherearr
[]
=
'
email IN (
'
.
simplode(
$emails
)
.
'
)
'
;
58
}
59
if
(
$touids
) {
60
$wherearr
[]
=
'
touid IN (
'
.
simplode(
$touids
)
.
'
)
'
;
61
}
62
63
if
(
$wherearr
) {
64
$query
=
$_SGLOBAL
[
'
db
'
]
->
query(
"
SELECT * FROM
"
.
tname(
'
mailqueue
'
)
.
"
WHERE
"
.
implode
(
'
OR
'
,
$wherearr
));
65
while
(
$value
=
$_SGLOBAL
[
'
db
'
]
->
fetch_array(
$query
)) {
66
if
(
$value
[
'
touid
'
]) {
67
$value
[
'
email
'
]
=
$useremails
[
$value
[
'
touid
'
]];
68
}
69
$sendmails
[
$value
[
'
email
'
]]
=
$value
[
'
email
'
];
70
$sends
[
$value
[
'
email
'
]][
'
subject
'
][]
=
$value
[
'
subject
'
];
71
$sends
[
$value
[
'
email
'
]][
'
message
'
][]
=
$value
[
'
message
'
];
72
$sends
[
$value
[
'
email
'
]][
'
dateline
'
][]
=
$value
[
'
dateline
'
];
73
}
74
//
删除当前已执行的队列
75
$_SGLOBAL
[
'
db
'
]
->
query(
"
DELETE FROM
"
.
tname(
'
mailcron
'
)
.
"
WHERE
"
.
implode
(
'
OR
'
,
$wherearr
));
76
$_SGLOBAL
[
'
db
'
]
->
query(
"
DELETE FROM
"
.
tname(
'
mailqueue
'
)
.
"
WHERE
"
.
implode
(
'
OR
'
,
$wherearr
));
77
78
//
更新用户最后发送时间
79
if
(
$touids
) {
80
$_SGLOBAL
[
'
db
'
]
->
query(
"
UPDATE
"
.
tname(
'
space
'
)
.
"
SET lastsend='
$_SGLOBAL
[timestamp]' WHERE uid IN (
"
.
simplode(
$touids
)
.
"
)
"
);
81
}
82
}
83
84
//
开始发送邮件
85
foreach
(
$sendmails
as
$email
) {
86
$thesend
=
$sends
[
$email
];
87
$subject
=
$thesend
[
'
subject
'
][
0
];
88
$message
=
''
;
89
foreach
(
$thesend
[
'
subject
'
]
as
$key
=>
$value
) {
90
$gmdateline
=
sgmdate(
'
m-d H:i
'
,
$thesend
[
'
dateline
'
][
$key
]);
91
if
(
$thesend
[
'
message
'
][
$key
]) {
92
$message
.=
"
<strong>
$value
</strong> (
"
.
$gmdateline
.
"
)
93
\n
"
.
$thesend
[
'
message
'
][
$key
]
.
"
94
95
\n
"
;
96
}
else
{
97
$message
.=
"
$value
(
"
.
$gmdateline
.
"
)
98
\n
"
;
99
}
100
}
101
sendmail(
array
(
$email
)
,
$subject
,
$message
);
102
}
103
104
?>