【问题标题】:How to configure WAMP (localhost) to send email using Gmail?如何配置 WAMP (localhost) 以使用 Gmail 发送电子邮件?
【发布时间】:2010-10-10 16:28:25
【问题描述】:

我想使用本地主机中的 mail() 函数。我安装了 WAMP 和一个 Gmail 帐户。我知道 Gmail 的 SMTP 是 smtp.gmail.com,端口是 465 (more info from gmail)。 我需要在 WAMP 中配置什么才能使用 mail() 函数?

谢谢!!

【问题讨论】:

    标签: php gmail localhost wamp


    【解决方案1】:

    我很肯定它也需要 SMTP 身份验证凭据。

    【讨论】:

      【解决方案2】:

      Gmail 服务器使用 SSL 或 TLS 下的 SMTP 身份验证。我认为在这种情况下无法使用 mail() 函数,因此您可能需要检查这些替代方法:

      它们都支持 SSL 下的 SMTP 身份验证。

      您需要在 php.ini 中启用 php_openssl 扩展。

      其他资源:

      【讨论】:

      • 你能告诉我确切的位置 $host = "ssl://smtp.gmail.com"; $端口 = 465; .?谢谢
      【解决方案3】:

      我知道在 XAMPP 中我可以配置 sendmail.ini 来转发本地电子邮件。 需要设置

      smtp_sever
      smtp_port
      auth_username
      auth_password
      

      这在使用我自己的服务器而不是 gmail 时有效,所以不能肯定你没有问题

      【讨论】:

        【解决方案4】:

        如果你在wamp中打开php.ini文件,你会发现这两行:

        smtp_server
        smtp_port
        

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

        以下两行不存在:

        auth_username
        auth_password
        

        因此,您需要添加它们才能从需要身份验证的服务器发送邮件。所以一个例子可能是:

        smtp_server = mail.example.com
        smtp_port = 26
        auth_username = example_username@example.com
        auth_password = example_password
        

        【讨论】:

        【解决方案5】:

        在您的服务器上使用 stunnel,通过 gmail 发送。谷歌一下。

        【讨论】:

          【解决方案6】:

          PEAR: Mail 为我从 Gmail 发送电子邮件工作。此外,说明:How to Send Email from a PHP Script Using SMTP Authentication(使用 PEAR::Mail)帮助很大。谢谢,CMS!

          【讨论】:

            【解决方案7】:

            这很简单。 (为方便起见调整语法)

            public $smtp = array(
                'transport' => 'Smtp',
                'from' => 'your_email@gmail.com',
                'host' => 'ssl://smtp.gmail.com',
                'port' => 465,
                'timeout' => 30,
                'username' => 'your_email@gmail.com',
                'password' => '*****'
            )
            

            【讨论】:

              【解决方案8】:

              作为 PHPMailer、Pear's Mail 和其他人的替代品,您可以使用 Zend's library

                $config = array('auth' => 'login',
                                 'ssl' => 'ssl',
                                 'port'=> 465,
                                 'username' => 'XXXX@gmail.com',
                                 'password' => 'XXXXXXX');
              
               $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
               $mail = new Zend_Mail();
               $mail->setBodyText('This is the text of the mail.');
               $mail->setFrom('XXXX@gmail.com', 'Some Sender');
               $mail->addTo('kazifriend@gmail.com', 'Some Recipient');
               $mail->setSubject('TestSubj');
               $mail->send($transport); 
              

              这是我在 localhost 服务器中的设置,我可以看到收到的邮件到我的邮箱。

              【讨论】:

                【解决方案9】:

                我在这里回答了这个问题:(WAMP/XAMP) send Mail using SMTP localhost(不仅适用于 GMAIL,也适用于其他人)。

                【讨论】:

                • 我需要在内存泄漏之前将此指令加入书签。
                • 遵循这些说明,与 hmailserver 5.6.4 和 gmail 帐户完美配合。如果您收到错误消息530 SMTP authentication is required,那么您需要按照最后的指示(p.s.)
                猜你喜欢
                • 2014-05-20
                • 2016-08-06
                • 2014-01-24
                • 1970-01-01
                • 1970-01-01
                • 2011-08-12
                • 2012-12-07
                • 2014-06-25
                • 2014-04-19
                相关资源
                最近更新 更多