[英]How to configure php.ini to use gmail as mail server
I want to learn yii as my first framework. 我想学习yii作为我的第一个框架。 And I'm trying to make the contact form work.
我正在努力使联系表格有效。 But I got this error:
但我得到了这个错误:
I've already configured php.ini file from: 我已经从以下位置配置了php.ini文件:
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 = myemail@gmail.com
I've seen from here that gmail doesn't use port 25, which is the default in the php.ini. 我从这里看到gmail不使用端口25,这是php.ini中的默认端口。 So I used 23. And also opened that port in the windows 7 firewall.
所以我用了23.而且还在windows 7防火墙中打开了那个端口。 Via inbound rules.
通过入站规则。
Then I also edited the main config in my yii application, to match the email that I'm using: 然后我也编辑了我的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',
),
);
Finally, I restarted wampserver. 最后,我重新启动了wampserver。 Then cleared all my browsing data.
然后清除了我的所有浏览数据。 Why then to I still see that its pointing out port 25 in the error.
为什么然后我仍然看到它指出错误中的端口25。 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. 下面是一个简单的python脚本,可以让你在localhost上运行一个邮件服务器,你不必改变任何东西。 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 注意:我使用args [3] [0]和args [4]作为地址和消息,因为我的php mail()发送的args对应于args [3] [0]的数组作为receipent email
If you open the php.ini
file in WAMP, you will find these two lines: 如果在WAMP中打开
php.ini
文件,您将找到以下两行:
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 = example_username@example.com
auth_password = example_password
ps: you should not use your personal mail here. ps:你不应该在这里使用你的个人邮件。 for an obvious reason.
原因很明显。
If using WAMP, the php.ini to be configured is present in the wamp/bin/apache/Apache_x_y/bin folder 如果使用WAMP,要配置的php.ini存在于wamp / bin / apache / Apache_x_y / bin文件夹中
where _x_y is related to the version of the Apache build used by your wamp installation 其中_x_y与您的wamp安装使用的Apache版本的版本相关
uncomment extension=php_openssl.dll at php.ini in WAMP server ("D:\\wamp\\bin\\apache\\Apache2.4.4\\bin\\php.ini") 在WAMP服务器的php.ini中取消注释extension = php_openssl.dll(“D:\\ wamp \\ bin \\ apache \\ Apache2.4.4 \\ bin \\ php.ini”)
In the file "D:\\wamp\\www\\mantisbt-1.2.15\\config_inc.php" 在文件“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 = 'yourmail@gmail.com'; $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 = '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 = 'Mantis Bug Tracker'; $g_email_receive_own = OFF; $g_email_send_using_cronjob = OFF;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.