php 如何配置 WAMP (localhost) 以使用 Gmail 发送电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/600725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:13:35  来源:igfitidea点击:

How to configure WAMP (localhost) to send email using Gmail?

phpgmaillocalhostwamp

提问by Jonathan

I want to use the mail() function from my localhost. I have WAMP installed and a Gmail account. I know that the SMTP for Gmail is smtp.gmail.com and the port is 465 (more info from gmail). What I need to configure in WAMP so I can use the mail() function?

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

Thanks!!

谢谢!!

采纳答案by CMS

Gmail servers use SMTP Authentication under SSL or TLS. I think that there is no way to use the mail()function under that circumstances, so you might want to check these alternatives:

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

They all support SMTP auth under SSL.

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

You'll need to enable the php_opensslextension in your php.ini.

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

Additional Resources:

其他资源:

回答by T.Todua

I've answered that here: (WAMP/XAMP) send Mail using SMTP localhost(works not only GMAIL, but for others too).

我在这里回答过:(WAMP/XAMP) 使用 SMTP localhost 发送邮件(不仅适用于 GMAIL,也适用于其他人)。

回答by T.Todua

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:

以下两行不存在:

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 = 26
auth_username = [email protected]
auth_password = example_password

回答by vinzcelavi

It's quite simple. (Adapt syntax for your convenience)

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

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

回答by kta

As an alternative to PHPMailer, Pear's Mail and others you could use the Zend's library

作为 PHPMailer、Pear's Mail 等的替代方案,您可以使用Zend 的库

  $config = array('auth' => 'login',
                   'ssl' => 'ssl',
                   'port'=> 465,
                   'username' => '[email protected]',
                   '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('[email protected]', 'Some Sender');
 $mail->addTo('[email protected]', 'Some Recipient');
 $mail->setSubject('TestSubj');
 $mail->send($transport); 

That is my set up in localhost server and I can able to see incoming mail to my mail box.

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

回答by abel

use stunnel on your server, to send with gmail. google it.

在您的服务器上使用 stunnel,通过 gmail 发送。去谷歌上查询。

回答by Scott Evernden

i know in XAMPP i can configure sendmail.ini to forward local email. need to set

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

smtp_sever
smtp_port
auth_username
auth_password

this works when using my own server, not gmail so can't say for certain you'd have no problems

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

回答by patricksweeney

I'm positive it would require SMTP authentication credentials as well.

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

回答by bhall

PEAR: Mailworked for me sending email messages from Gmail. Also, the instructions: How to Send Email from a PHP Script Using SMTP Authentication(Using PEAR::Mail) helped greatly. Thanks, CMS!

PEAR:邮件为我从 Gmail 发送电子邮件。此外,说明: How to Send Email from a PHP Script Using SMTP Authentication(Using PEAR::Mail) 也有很大帮助。谢谢,内容管理系统!