本文介绍了如何配置php.ini以使用Gmail作为邮件服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习yii作为我的第一个框架。我正在努力使联系表单工作。但我得到这个错误:



我已经配置了php.ini文件:

  C:\wamp\bin\php\\ \\ php5.3.0 

然后将默认值更改为以下值:

  [邮件功能] 
;仅适用于Win32。
; http://php.net/smtp
SMTP = ssl:smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 23

;仅适用于Win32。
; http://php.net/sendmail-from
sendmail_from = [email protected]

我从这里看到,gmail不使用端口25,这是php.ini中的默认端口。所以我使用了23.并且还在Windows 7防火墙中打开了该端口。通过入站规则。

然后,我还编辑了我的yii应用程序中的主配置,以匹配我使用的电子邮件:

  //可以访问的应用程序级参数
//使用Yii :: app() - > params ['paramName']
'params'=>数组(
//这用于联系人页面
'adminEmail'=> [email protected]',
),
) ;

最后,我重新启动了wampserver。然后清除我所有的浏览数据。为什么然后我仍然看到它指出错误中的端口25。我想念什么?请帮助。

解决方案

下面是一个简单的python脚本,它可以让您在本地主机上运行邮件服务器,您不必更改任何东西。

 进口smtpd 

进口smtplib

import asyncore
$ b $ class SMTPServer(smtpd.SMTPServer):

def __init __(* args,** kwargs):
print在端口上运行假的smtp服务器25
smtpd.SMTPServer .__ init __(* args,** kwargs)

def process_message(* args,** kwargs):
to = args [3] [0 ]
msg = args [4]
gmail_user ='yourgmailhere'
gmail_pwd ='yourgmailpassword'
smtpserver = smtplib.SMTP(smtp.gmail.com,587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user,gmail_pwd)
smtpserver.sendmail(gmail_user,to,msg)如果__name__ ==__main__:
smtp_server = SMTPServer(('localhost',25),None)
print'sent to'+ to
pass


试试:
asyncore.loop()
ex cept KeyboardInterrupt:
smtp_server.close()

#end of code



注意:我使用args [3] [0]和args [4]作为地址和消息,因为我的PHP邮件()发送的参数对应于args [3] [0]的数组作为receipent电子邮件


I want to learn yii as my first framework. And I'm trying to make the contact form work. But I got this error:

I've already configured php.ini file from:

C:\wamp\bin\php\php5.3.0

And changed the default to these values:

 [mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = ssl:smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 23

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]

I've seen from here that gmail doesn't use port 25, which is the default in the php.ini. So I used 23. And also opened that port in the windows 7 firewall. Via inbound rules.

Then I also edited the main config in my yii application, to match the email that I'm using:

// application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params'=>array(
        // this is used in contact page
        'adminEmail'=>'[email protected]',
    ),
);

Finally, I restarted wampserver. Then cleared all my browsing data. Why then to I still see that its pointing out port 25 in the error. Have I miss something? Please help.

解决方案

Heres a simple python script which could allow you to run a mail server on localhost, you dont have to change anything. Sorry if im a bit late.

import smtpd

import smtplib

import asyncore

class SMTPServer(smtpd.SMTPServer):

    def __init__(*args, **kwargs):
        print "Running fake smtp server on port 25"
        smtpd.SMTPServer.__init__(*args, **kwargs)

    def process_message(*args, **kwargs):
        to = args[3][0]
        msg = args[4]
        gmail_user = 'yourgmailhere'
        gmail_pwd = 'yourgmailpassword'
        smtpserver = smtplib.SMTP("smtp.gmail.com",587)
        smtpserver.ehlo()
        smtpserver.starttls()
        smtpserver.ehlo
        smtpserver.login(gmail_user, gmail_pwd)
        smtpserver.sendmail(gmail_user, to, msg)
        print 'sent to '+to
        pass

if __name__ == "__main__":
    smtp_server = SMTPServer(('localhost', 25), None)
    try:
        asyncore.loop()
    except KeyboardInterrupt:
        smtp_server.close()

#end of code

Note: I used args[3][0] and args[4] as to address and message as the args sent by my php mail() corresponded to an array of args[3][0] as receipent email

这篇关于如何配置php.ini以使用Gmail作为邮件服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 11:12