【问题标题】:How to configure php.ini to use gmail as mail server如何配置 php.ini 以使用 gmail 作为邮件服务器
【发布时间】:2011-05-04 23:06:22
【问题描述】:

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

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

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

并将默认值更改为这些值:

 [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 防火墙中打开了该端口。通过入站规则。

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

// 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。我错过了什么吗?请帮忙。

【问题讨论】:

  • 端口 25 和 23 都是错误的。此外,gmail 仅在授权后接受 smtp。因此,您还必须在某处输入您的用户名和密码。见mail.google.com/support/bin/answer.py?hl=en&answer=13287我不知道yii是否可以使用TLS或SSL发送邮件
  • 如果您使用 SSL,请输入 465。如果您使用 TLS,请输入 587。

标签: smtp gmail wamp php


【解决方案1】:

这是一个简单的 python 脚本,可以让您在本地主机上运行邮件服务器,您无需更改任何内容。对不起,如果我有点晚了。

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] 数组作为接收电子邮件

【讨论】:

  • process_message 在我尝试通过 php 中的mail() 发送后未调用
  • 这超出了问题的范围,停止为代表钓鱼
  • 天啊!服务器假它工作正常,我创建文件 python 运行。并且在 php.ini 文件中默认不修复任何东西。我收到了电子邮件。谢谢!!
【解决方案2】:

如果你在 WAMP 中打开 php.ini 文件,你会发现这两行:

smtp_server
smtp_port

为您的主机添加服务器和端口号(您可能需要联系他们了解详细信息)

以下两行默认不存在:

auth_username
auth_password

因此,您需要添加它们才能从需要身份验证的服务器发送邮件。所以一个例子可能是:

smtp_server = mail.example.com
smtp_port = 25
auth_username = example_username@example.com
auth_password = example_password

ps:你不应该在这里使用你的私人邮件。原因很明显。

【讨论】:

  • 非常感谢您的格式化。因为我是新手,所以我不知道规则。和降价风格.. @DACrosby
【解决方案3】:

如果使用 WAMP,要配置的 php.ini 存在于 wamp/bin/apache/Apache_x_y/bin 文件夹中

其中 _x_y 与 wamp 安装使用的 Apache 构建版本有关

【讨论】:

    【解决方案4】:
    1. 在 WAMP 服务器的 php.ini 中取消注释 extension=php_openssl.dll(“D:\wamp\bin\apache\Apache2.4.4\bin\php.ini”)

    2. 在文件“D:\wamp\www\mantisbt-1.2.15\config_inc.php”中

    # --- 电子邮件配置 --- $g_phpMailer_method = PHPMAILER_METHOD_SMTP; $g_smtp_host = 'smtp.gmail.com'; $g_smtp_connection_mode = 'ssl'; $g_smtp_port = 465; $g_smtp_username = '你的邮件@gmail.com'; $g_smtp_password = '你的密码'; $g_enable_email_notification = ON; $g_log_level = LOG_EMAIL | LOG_EMAIL_RECIPIENT; $g_log_destination = '文件:/tmp/log/mantisbt.log'; $g_administrator_email = 'administrator@example.com'; $g_webmaster_email = 'webmaster@example.com'; $g_from_email = 'noreply@example.com'; $g_return_path_email = 'admin@example.com'; $g_from_name = '螳螂漏洞追踪器'; $g_email_receive_own = 关闭; $g_email_send_using_cronjob = 关闭;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-26
      • 2011-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多