Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure php.ini to use gmail as mail server

Tags:

php

smtp

gmail

wamp

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.

like image 348
user225269 Avatar asked Nov 04 '10 09:11

user225269


1 Answers

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

like image 144
ppsreejith Avatar answered Sep 23 '22 05:09

ppsreejith