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

发布于 2024-10-01 02:30:13 字数 1145 浏览 4 评论 0原文

我想学习 yii 作为我的第一个框架。我正在努力使联系表格发挥作用。但我收到了这个错误: alt text

我已经配置了 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 = [email protected]

我已经看到这里 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'=>'[email protected]',
    ),
);

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

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 text

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无法回应 2024-10-08 02:30:13

这是一个简单的 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[3][0] 数组

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

美胚控场 2024-10-08 02:30:13

如果您在 WAMP 中打开 php.ini 文件,您会发现以下两行:

smtp_server
smtp_port

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

以下两行不会默认情况下不存在:

auth_username
auth_password

因此您需要添加它们才能从需要身份验证的服务器发送邮件。例如:

smtp_server = mail.example.com
smtp_port = 25
auth_username = [email protected]
auth_password = example_password

ps:您不应该在此处使用您的个人邮件。原因很明显。

If you open the php.ini file in WAMP, you will find these two lines:

smtp_server
smtp_port

Add the server and port number for your host (you may need to contact them for details)

The following two lines don't exist by default:

auth_username
auth_password

So you will need to add them to be able to send mail from a server that requires authentication. So an example may be:

smtp_server = mail.example.com
smtp_port = 25
auth_username = [email protected]
auth_password = example_password

ps: you should not use your personal mail here. for an obvious reason.

哥,最终变帅啦 2024-10-08 02:30:13

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

,其中 _x_y 与 wamp 安装使用的 Apache 版本相关

If using WAMP, the php.ini to be configured is present in the wamp/bin/apache/Apache_x_y/bin folder

where _x_y is related to the version of the Apache build used by your wamp installation

初心 2024-10-08 02:30:13
  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 ”

    # --- Email Configuration ---

    $g_phpMailer_method = PHPMAILER_METHOD_SMTP; 
    $g_smtp_host = 'smtp.gmail.com';
    $g_smtp_connection_mode = 'ssl';
    $g_smtp_port = 465;
    $g_smtp_username        = '[email protected]'; 
    $g_smtp_password        = 'yourpwd';
    $g_enable_email_notification = ON;
    $g_log_level = LOG_EMAIL | LOG_EMAIL_RECIPIENT;
    $g_log_destination = 'file:/tmp/log/mantisbt.log';  
    $g_administrator_email  = '[email protected]';
    $g_webmaster_email      = '[email protected]';
    $g_from_email           = '[email protected]';
    $g_return_path_email    = '[email protected]';  
    $g_from_name            = 'Mantis Bug Tracker';
    $g_email_receive_own    = OFF;
    $g_email_send_using_cronjob = OFF;
  1. uncomment extension=php_openssl.dll at php.ini in WAMP server ("D:\wamp\bin\apache\Apache2.4.4\bin\php.ini")

  2. In the file "D:\wamp\www\mantisbt-1.2.15\config_inc.php"

    # --- Email Configuration ---

    $g_phpMailer_method = PHPMAILER_METHOD_SMTP; 
    $g_smtp_host = 'smtp.gmail.com';
    $g_smtp_connection_mode = 'ssl';
    $g_smtp_port = 465;
    $g_smtp_username        = '[email protected]'; 
    $g_smtp_password        = 'yourpwd';
    $g_enable_email_notification = ON;
    $g_log_level = LOG_EMAIL | LOG_EMAIL_RECIPIENT;
    $g_log_destination = 'file:/tmp/log/mantisbt.log';  
    $g_administrator_email  = '[email protected]';
    $g_webmaster_email      = '[email protected]';
    $g_from_email           = '[email protected]';
    $g_return_path_email    = '[email protected]';  
    $g_from_name            = 'Mantis Bug Tracker';
    $g_email_receive_own    = OFF;
    $g_email_send_using_cronjob = OFF;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文