装了个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/文件夹下面就可以了.
<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: sendmail.php 8302 2008-08-01 02:10:28Z liguode $
*/
if(!defined('IN_UCHOME')) {
exit('Access Denied');
}
//防止超时
set_time_limit(0);
//一次发送邮件个数
$pernum = 5;
include_once(S_ROOT.'./source/function_sendmail.php');
//获取发送队列
$emails = $touids = array();
$query = $_SGLOBAL['db']->query("SELECT touid, email FROM ".tname('mailcron')." WHERE sendtime<='$_SGLOBAL[timestamp]' ORDER BY sendtime LIMIT 0,$pernum");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($value['email']) {
$emails[$value['email']] = $value['email'];
} elseif ($value['touid']) {
$touids[$value['touid']] = $value['touid'];
}
}
//获取用户邮件
$useremails = $deluids = array();
if($touids) {
$query = $_SGLOBAL['db']->query("SELECT sf.emailcheck, sf.email, s.uid, s.lastsend, s.updatetime
FROM ".tname('space')." s
LEFT JOIN ".tname('spacefield')." sf ON sf.uid=s.uid
WHERE s.uid IN (".simplode($touids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($_SCONFIG['sendmailday'] && $value['emailcheck'] && $value['email'] && ($_SGLOBAL['timestamp'] - $value['lastlogin'] > $_SCONFIG['sendmailday']*86400)) {
$useremails[$value['uid']] = $value['email'];
} else {
$deluids[$value['uid']] = $value['uid'];
unset($touids[$value['uid']]);
}
}
}
//删除无效的用户邮件
if($deluids) {
$_SGLOBAL['db']->query("DELETE FROM ".tname('mailcron')." WHERE touid IN (".simplode($deluids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('mailqueue')." WHERE touid IN (".simplode($deluids).")");
}
//获取邮件队列
$wherearr = $sends = $sendmails = array();
if($emails) {
$wherearr[] = 'email IN ('.simplode($emails).')';
}
if($touids) {
$wherearr[] = 'touid IN ('.simplode($touids).')';
}
if($wherearr) {
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('mailqueue')." WHERE ".implode(' OR ', $wherearr));
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($value['touid']) {
$value['email'] = $useremails[$value['touid']];
}
$sendmails[$value['email']] = $value['email'];
$sends[$value['email']]['subject'][] = $value['subject'];
$sends[$value['email']]['message'][] = $value['message'];
$sends[$value['email']]['dateline'][] = $value['dateline'];
}
//删除当前已执行的队列
$_SGLOBAL['db']->query("DELETE FROM ".tname('mailcron')." WHERE ".implode(' OR ', $wherearr));
$_SGLOBAL['db']->query("DELETE FROM ".tname('mailqueue')." WHERE ".implode(' OR ', $wherearr));
//更新用户最后发送时间
if($touids) {
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET lastsend='$_SGLOBAL[timestamp]' WHERE uid IN (".simplode($touids).")");
}
}
//开始发送邮件
foreach ($sendmails as $email) {
$thesend = $sends[$email];
$subject = $thesend['subject'][0];
$message = '';
foreach ($thesend['subject'] as $key => $value) {
$gmdateline = sgmdate('m-d H:i', $thesend['dateline'][$key]);
if($thesend['message'][$key]) {
$message .= "<strong>$value</strong> (".$gmdateline.")
\n".$thesend['message'][$key]."
\n";
} else {
$message .= "$value (".$gmdateline.")
\n";
}
}
sendmail(array($email), $subject, $message);
}
?>