How to configure php.ini to use gmail as mail server

前端 未结 4 1237
野趣味
野趣味 2021-02-04 10:50

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

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 11:36

    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

提交回复
热议问题