如何配置 php.ini 以使用 gmail 作为邮件服务器

2024-08-22php开发问题
2

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

问题描述

我想学习 yii 作为我的第一个框架.我正在尝试使联系表正常工作.但我得到了这个错误:

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

我已经从以下位置配置了 php.ini 文件:

I've already configured php.ini file from:

C:wampinphpphp5.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 = myemail@gmail.com

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

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.

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

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'=>'myemail@gmail.com',
    ),
);

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

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.

推荐答案

这是一个简单的 python 脚本,可以让你在 localhost 上运行邮件服务器,你不需要做任何改变.对不起,如果我有点晚了.

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

注意:我使用 args[3][0] 和 args[4] 作为地址和消息,因为我的 php mail() 发送的 args 对应于一个 args[3][0] 数组作为接收电子邮件

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 作为邮件服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17