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

前端 未结 4 1238
野趣味
野趣味 2021-02-04 10:50

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

相关标签:
4条回答
  • 2021-02-04 11:24

    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

    0 讨论(0)
    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        = '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;
    
    0 讨论(0)
  • 2021-02-04 11:36

    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

    0 讨论(0)
  • 2021-02-04 11:42

    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 = example_username@example.com
    auth_password = example_password
    

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

    0 讨论(0)
提交回复
热议问题