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

时间:2023-01-12 23:44:37

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?

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

Thanks!!

谢谢!!

9 个解决方案

#1


27  

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_openssl extension in your php.ini.

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

Additional Resources:

其他资源:

#2


13  

[Using hMailServer]
After installation, you need the following configuration to properly send mail from wampserver:

[使用hMailServer]安装后,您需要以下配置才能从wampserver正确发送邮件:

1) When you first open hMailServer Administrator, you need to add a new domain.
2) Click on the "Add Domain ..." button at the Welcome page. 
3) Under the domain text field, enter your computer's IP, in this case it should be 127.0.0.1.
4) Click on the Save button.
5) Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
6) Enter "localhost" in the localhost name field.
7) Click on the Save button.

If you need to send mail using a FROM addressee of another computer, you need to allow deliveries from External to External accounts. To do that, follow these steps:

如果您需要使用另一台计算机的FROM收件人发送邮件,则需要允许从外部帐户到外部帐户的交付。为此,请按照下列步骤操作:

1) Go to Settings>Advanced>IP Ranges and double click on "My Computer" which should have IP address of 127.0.0.1
2) Check the Allow Deliveries from External to External accounts checkbox.
3) Save settings using Save button.

(However, Windows Live/Hotmail has denied all emails coming from dynamic IPs, which most residential computers are using. The workaround is to use Gmail account )

(但是,Windows Live / Hotmail拒绝来自动态IP的所有电子邮件,这是大多数住宅计算机正在使用的。解决方法是使用Gmail帐户)

To use Gmail account :

1) Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
2) Enter "smtp.gmail.com" in the Remote Host name field.
3) Enter "465" as the port number
4) Check "Server requires authentication"
5) Enter gmail address in the Username
6) Enter gmail password in the password 
7) Check "Use SSL"

(Note, "From" field doesnt function with gmail)

(注意,“From”字段不能与gmail一起使用)


*p.s. in rare cases, there may be needed to untick everything under require SMTP authentication in :

* P.S。在极少数情况下,可能需要在需要SMTP身份验证的情况下取消所有内容:

  • for local : Settings>Advanced>IP Ranges>"My Computer"
  • for local:设置>高级> IP范围>“我的电脑”
  • for external : Settings>Advanced>IP Ranges>"Internet"
  • for external:设置>高级> IP范围>“Internet”

#3


11  

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

#4


2  

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所以不能肯定地说你没有问题

#5


2  

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

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

#6


2  

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

这很简单。 (为方便起见,修改语法)

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' => '*****'
)

#7


2  

Do you like Zend library?

你喜欢Zend图书馆吗?

  $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); 

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

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

#8


1  

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

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

#9


1  

PEAR: Mail worked 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:Mail为我发送Gmail发送电子邮件。此外,说明:如何使用SMTP身份验证(使用PEAR :: Mail)从PHP脚本发送电子邮件有很大帮助。谢谢,CMS!

#1


27  

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_openssl extension in your php.ini.

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

Additional Resources:

其他资源:

#2


13  

[Using hMailServer]
After installation, you need the following configuration to properly send mail from wampserver:

[使用hMailServer]安装后,您需要以下配置才能从wampserver正确发送邮件:

1) When you first open hMailServer Administrator, you need to add a new domain.
2) Click on the "Add Domain ..." button at the Welcome page. 
3) Under the domain text field, enter your computer's IP, in this case it should be 127.0.0.1.
4) Click on the Save button.
5) Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
6) Enter "localhost" in the localhost name field.
7) Click on the Save button.

If you need to send mail using a FROM addressee of another computer, you need to allow deliveries from External to External accounts. To do that, follow these steps:

如果您需要使用另一台计算机的FROM收件人发送邮件,则需要允许从外部帐户到外部帐户的交付。为此,请按照下列步骤操作:

1) Go to Settings>Advanced>IP Ranges and double click on "My Computer" which should have IP address of 127.0.0.1
2) Check the Allow Deliveries from External to External accounts checkbox.
3) Save settings using Save button.

(However, Windows Live/Hotmail has denied all emails coming from dynamic IPs, which most residential computers are using. The workaround is to use Gmail account )

(但是,Windows Live / Hotmail拒绝来自动态IP的所有电子邮件,这是大多数住宅计算机正在使用的。解决方法是使用Gmail帐户)

To use Gmail account :

1) Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
2) Enter "smtp.gmail.com" in the Remote Host name field.
3) Enter "465" as the port number
4) Check "Server requires authentication"
5) Enter gmail address in the Username
6) Enter gmail password in the password 
7) Check "Use SSL"

(Note, "From" field doesnt function with gmail)

(注意,“From”字段不能与gmail一起使用)


*p.s. in rare cases, there may be needed to untick everything under require SMTP authentication in :

* P.S。在极少数情况下,可能需要在需要SMTP身份验证的情况下取消所有内容:

  • for local : Settings>Advanced>IP Ranges>"My Computer"
  • for local:设置>高级> IP范围>“我的电脑”
  • for external : Settings>Advanced>IP Ranges>"Internet"
  • for external:设置>高级> IP范围>“Internet”

#3


11  

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

#4


2  

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所以不能肯定地说你没有问题

#5


2  

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

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

#6


2  

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

这很简单。 (为方便起见,修改语法)

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' => '*****'
)

#7


2  

Do you like Zend library?

你喜欢Zend图书馆吗?

  $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); 

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

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

#8


1  

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

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

#9


1  

PEAR: Mail worked 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:Mail为我发送Gmail发送电子邮件。此外,说明:如何使用SMTP身份验证(使用PEAR :: Mail)从PHP脚本发送电子邮件有很大帮助。谢谢,CMS!