2010-11-04 77 views
9

我想學習yii作爲我的第一個框架。我正在努力使聯繫表單工作。但我得到這個錯誤: alt text如何配置php.ini以使用Gmail作爲郵件服務器

我已經從配置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。我想念什麼?請幫忙。

+0

有人在家???呵呵 – user225269 2010-11-07 08:24:34

+2

端口25和23都是錯誤的。此外,gmail只在授權後才接受smtp。所以你也必須輸入你的用戶名和密碼。請參閱http://mail.google.com/support/bin/answer.py?hl=zh_CN&answer=13287我不知道yii是否能夠使用TLS或SSL發送郵件 – wimh 2010-12-27 13:40:57

回答

4

下面是一個簡單的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郵件發送的ARGS對應成參數的陣列[3] [0]作爲receipent電子郵件使用WAMP

+0

未調用process_message在我試圖通過郵件發送()後,在php – 2013-10-22 05:38:26

0

如果在php.ini中配置出現在WAMP /斌/阿帕奇/ Apache_x_y/bin文件夾

其中_x_y涉及到Apache的版本共建使用您的wamp installation

3

如果你在WAMP中打開php.ini文件,你會發現這兩個li網元:

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:你不應該在這裏使用你的私人郵件。原因很明顯。

+0

中非常感謝你格式化..因爲我是新的,我不知道規則。和減價風格。 @DACrosby – 2013-09-30 07:00:08

0
  1. 取消註釋延長=在WAMP服務器php_openssl.dll在php.ini中( 「d:\瓦帕\ BIN \阿帕奇\ 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; 
相關問題