在windows搭建PHP环境,配置比较麻烦,所以一般采用别人封装好的PHP组件,明晨网络MingchenNet.com使用的是phpnow。
明晨网络MingchenNet.com使用GOOGLE强力驱动的企业邮局标准版。google使用了安全的ssl加密的smtp协议,所以在php下连接GMAIL时,需要做一番设置,使其支持ssl。这里给出明晨网络MingchenNet.com的测试结论。
使用iProber.php探针查看PHP环境,phpnow默认安装是不支持Socket的,如果连接普通的smtp服务器没有问题,连接ssl加密的smtp服务器就提示:SMTP Error:Could not connect to SMTP host 。这需要打开php的socket和openssl组件,通过修改PHP.INI配置文件来实现。phpnow的配置文件PHP.INI位于c:/windows目录下,而非c:/programe files/php_iis下!
首先,打开c:/windows/php.ini文件,去掉下面两行前的分号,然后保存。
;extension=php_sockets.dll
;extension=php_openssl.dll
然后,复制C:/Program Files/php_iis/php/libeay32.dll 和ssleay32.dll到c:/windows/system32目录下,重启IIS。
ok,使用phpmailer测试你的gmail吧。
-
<?php
-
include ( "class.phpmailer.php" ) ; //加载phpmailer主类,一般情况下要设定好phpmailer路径
-
include ( "class.smtp.php" ) ; // 加载smtp类,一般情况下要设定好phpmailer路径
-
$mail = new PHPMailer ( ) ;
-
$mail -> IsSMTP ( ) ; // 使用SMTP
-
$mail -> SMTPSecure = "ssl" ;
-
$mail -> Host = "smtp.gmail.com";
-
$mail -> Port = 465 ; // GMAIL的SMTP端口号
-
$mail -> SMTPAuth = true ; // 开启SMTP认证
-
$mail -> Username = "mingchennet@gmail.com" ; // GMAIL用户名
-
$mail -> Password = "password" ; // GMAIL密码
-
$webmaster_email = "mingchennet@gmail.com" ; //回复到该地址
-
$email = "mingchennet@gmail.com" ; // 收件人
-
$name = "明晨网络" ; // 收件人名称
-
$mail -> From = $webmaster_email ;
-
$mail -> FromName = "明晨网络" ;
-
$mail -> AddAddress ( $email , $name ) ;
-
$mail -> AddReplyTo ( $webmaster_email , "明晨网络" ) ;
-
$mail -> WordWrap = 50 ; // 设定 word wrap
-
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 附件1
-
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // 附件2
-
$mail -> IsHTML ( true ) ; // 以HTML发送
-
$mail -> Subject = "This is the subject" ;
-
$mail -> Body = "Hi,
-
This is the HTML BODY " ; //HTML Body
-
$mail -> AltBody = "This is the body when user views in plain text format" ; //纯文字时的Body
-
if ( ! $mail -> Send ( ) )
-
{
-
echo "Mailer Error: " . $mail -> ErrorInfo ;
-
}
-
else
-
{
-
echo "Message has been sent" ;
-
}
-
?>