搭建本地邮件服务器

XAMPP 自带的邮件服务器名称是 Mercury。架设你已经启动了 Apache 和 MySQL,现在点击 XAMPP 根目录下的 mercury_start.bat 就能直接启动邮件服务器;或者,你通过上面提到的 Control Panel 也能启动 Mercury 邮件服务器。

1.就这么一步,Mercury 邮件服务器已经运行起来并且能够发送邮件了。不过,只能通过 Mercury 本身来发送。我们先测试一下这个功能。

在 Mercury 主面板上点击顶部菜单“File -> Send mail message”,就会弹出一个简单的邮件撰写窗口,填写你自己的正规信箱作为收件人,随便编造一个主题和正文,点击“Send”发送出去。我是用 Gmail 的信箱来测试的,大概2分钟就收到了。看下面两个截图:

Mercury test mail received

但是,这个时候如果你使用前面介绍的 SMTP 帐号来尝试设置 Joomla 后台邮件设置,或者尝试用 Outlook Express 借助这个 SMTP 来发送邮件,都会失败。Joomla 的错误消息没有提供什么有价值的参考,而 OE 会提示你:

553 We do not relay non-local mail, sorry

下面我们来解决这个问题,其实只是一个小小的设置而已:

2、设置 Mercury 邮件服务器及默认帐号的密码

点击 Mercury 顶部菜单的“Configuration -> MercuryS SMTP Server” ,在弹出的对话框上点击“Connection control”标签页,去掉“Do not permit SMTP relaying of non-local mail”这一项的勾选,然后点击“确定”。

Mercury SMTP server settings

去掉上面一项之后,就可以向外发送邮件了。不过,Mercury 的默认帐号是没有密码的,必须设置一个密码才能连接 SMTP 服务器。为了方便记忆,我们这个测试帐号的密码就设为与用户名相同吧:都是 postmaster。

如下图操作:点击 Mercury 主面板顶部菜单上“Configuration -> Manage local users”,在弹出的对话框上选定 postmaster 这个用户,点击右边的“Change”按钮,然后在弹出的对话框中“Mail password”这里填写 postmaster,点击“OK”即可。

经过这两点设置,Mercury 邮件服务器就完全可以用来向外发送邮件了。接下来你要在 Joomla 后台设置这个 SMTP 帐号:

3、在 Joomla 中使用 Mercury 的 SMTP 服务器

以管理员身份登录到 Joomla 1.5.x 后台,点击控制面板上的“全局设置”,进入“服务器”标签页,在“邮件设置”这里按下图所示填写:

Joomla use Mercury SMTP server

首先选择“SMTP 服务器”模式。寄件人地址填写 postmaster@localhost 。由于 Mercury 的 SMTP 服务器默认不需要验证,所以在“SMTP 认证”这里选择“否”。用户名和密码都是 postmaster,主机就是 SMTP 服务器的地址,这里填写“localhost”,端口是默认的 25。

如果你需要在 Outlook Express 里面利用这个本地的 Mercury 邮件服务器来收发邮件,也可以按照上述参数来设置。POP3 服务器的地址仍然是 localhost,端口是 110。

到现在就大功告成了。你保存全局设置之后,可以在前台分别测试一下注册新会员和通过联系人表单发送邮件,应该能收到了。

最后提醒一下:有人可能还想玩玩“邮件设置”里面的 Sendmail 模式,这几乎没什么意义。

Sendmail 本来是 Linux 平台的程序,在 XAMPP for Windows 里面,也有一个 sendmail.exe 文件,这只能算是“伪 sendmail”(fake Sendmail),而不是真正的 sendmail。

之所以说它是“伪 sendmail”,是因为在 Windows 平台上,这个 sendmail.exe 实际上是通过 SMTP 服务器来发送邮件的,而不是靠它本身。也就是说,如果你想玩 sendmail,那么还必须按照上面所说的设置,完全调整好 Mercury 的 SMTP 服务器,现在选择 Sendmail 模式就能正常工作了。但这有什么意义呢?还不如直接用 SMTP 参数来发送。

一旦把sendmail_from设置为一个email地址,PHP会强制所有发送方地址为设置值。
在XAMPP Control Panel里开启mail服务Mercury后,在PHP中仍然可能会遇到这样的错误

553 We do not relay non-local mail

这需要对Mercury的配置做些修改
Configuration->Mercury SMTP Server->Connection control
去掉Do not permit SMTP relaying of non-local mail前的钩。

最后一步可能不是必要的。
如果发送邮件时从Mercury SMTP client里看到类似找不到XXX.com的信息的话,可能是DNS没有配置好的关系。找到xampp\MercuryMail\MERCURY.INI,配置相应的DNS。

94
Nameservers : 192.168.1.100,172.16.119.12

现在,应该可以收发邮件了。sohu的邮箱有反向域名解析,如果域名不合法是拒收邮件的。QQ邮箱则会收取,但会直接丢到垃圾邮件里去。



用sendmail来发批量邮件功能。

如果不用xampp的话,去下载个,如果用,刚按下面几步配置即可。

1.使用sendmail 修改 D:\xampp\sendmail\sendmail.ini

php在windows配置下sendmail 详解 图解 完全攻略

php在windows配置下sendmail 详解 图解 完全攻略

具体内容是:
[sendmail]
smtp_server=mail.test.com
; smtp port (normally 25)
smtp_port=25
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify
default_domain=test.com
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=info@test.com
auth_password=testpassword

配置以上几个参数即可

2.使用php sendmail修改 D:\xampp\apache\bin\php.ini 修改如下:

php在windows配置下sendmail 详解 图解 完全攻略

具体内容如下:

[mail function]
; For Win32 only.
SMTP = mail.test.com
smtp_port = 25

; For Win32 only.
sendmail_from = info@test.com
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "D:\xampp\sendmail\sendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

3. 重新启动 Apache,O定完!

4. 使用php sendmailymail()功能

php在windows配置下sendmail 详解 图解 完全攻略

<?php
$now = date('Y-m-d h:i:s');
$from_name = '测试寄件人';
$from_email = 'info@test.com';
$headers = "From: $from_name <$from_email>";
$to = 'to@test.com';  //收件人邮件地址
$body = "嗨, \n 这是一封测试邮件来自 $from_name <$from_email>.";
$subject = "[$now] 测试邮件发送";
if (mail($to, $subject, $body, $headers)) {
echo 'success!';
} else {
echo 'fail…';
}
?>

这样,Windows下使用php sendmail配置就顺利完成了!

执行完之后,再看D:\xampp\sendmail\目录,会多出几个文件

php在windows配置下sendmail 详解 图解 完全攻略

php在windows配置下sendmail 详解 图解 完全攻略

具体一些内容大家试完自己看吧,error.log还是能有帮助的




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值