PHPMailer IIS下的PHP脚本使用GMAIL发送邮件

 在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吧。

 

 

  1. <?php
  2. include ( "class.phpmailer.php" ) ; //加载phpmailer主类,一般情况下要设定好phpmailer路径
  3. include ( "class.smtp.php" ) ;  // 加载smtp类,一般情况下要设定好phpmailer路径
  4. $mail   =  new PHPMailer ( ) ;
  5. $mail -> IsSMTP ( ) ;  // 使用SMTP
  6. $mail -> SMTPSecure  =  "ssl" ;
  7. $mail -> Host  =  "smtp.gmail.com";
  8. $mail -> Port  =  465 ;                    // GMAIL的SMTP端口号
  9. $mail -> SMTPAuth  =  true ;  // 开启SMTP认证
  10. $mail -> Username  =  "mingchennet@gmail.com" ;  // GMAIL用户名
  11. $mail -> Password  =  "password" ;  // GMAIL密码
  12. $webmaster_email  =  "mingchennet@gmail.com" ;  //回复到该地址
  13. $email = "mingchennet@gmail.com" ;  // 收件人
  14. $name = "明晨网络" ;  // 收件人名称
  15. $mail -> From  =  $webmaster_email ;
  16. $mail -> FromName  =  "明晨网络" ;
  17. $mail -> AddAddress ( $email , $name ) ;
  18. $mail -> AddReplyTo ( $webmaster_email , "明晨网络" ) ;
  19. $mail -> WordWrap  =  50 ;  // 设定 word wrap
  20. //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 附件1
  21. //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // 附件2
  22. $mail -> IsHTML ( true ) ;  // 以HTML发送
  23. $mail -> Subject  =  "This is the subject" ;
  24. $mail -> Body  =  "Hi,
  25. This is the HTML BODY " ;  //HTML Body
  26. $mail -> AltBody  =  "This is the body when user views in plain text format" ;  //纯文字时的Body
  27. if ( ! $mail -> Send ( ) )
  28. {
  29. echo  "Mailer Error: "  .  $mail -> ErrorInfo ;
  30. }
  31. else
  32. {
  33. echo  "Message has been sent" ;
  34. }
  35. ?>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值