php 如何从本地 WAMP 服务器发送电子邮件以发送电子邮件 Gmail Hotmail 等?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22396721/
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-25 04:53:45  来源:igfitidea点击:

How to send email from localhost WAMP Server to send email Gmail Hotmail or so forth?

phpemaillocalhostwamp

提问by Jay Patel

I'm finding to proper information about how to send email from localhost WAMP. And how to get authorize to send email from particular authorize email address to send any other email address.

我正在查找有关如何从 localhost WAMP 发送电子邮件的正确信息。以及如何获得授权从特定授权电子邮件地址发送电子邮件以发送任何其他电子邮件地址。

How to configure this whole step explain me details, I already visit here some Stack Overflow answer as well as blog post but all are very confusing and old dated so it's may be possible to not working. So i need Stack Overflow users help. Thank you.

如何配置这整个步骤向我解释了详细信息,我已经在这里访问了一些 Stack Overflow 答案以及博客文章,但所有内容都非常混乱且过时,因此可能无法正常工作。所以我需要 Stack Overflow 用户的帮助。谢谢你。

采纳答案by Jay Patel

Configuring a working email client from localhostis quite a chore, I have spent hours of frustration attempting it. At last I have found this way to send mails (using WAMP, XAMPP, etc.):

配置一个工作的电子邮件客户端localhost是一件很麻烦的事,我花了几个小时的挫折尝试它。最后我找到了这种发送邮件的方式(使用 WAMP、XAMPP 等):

Install hMailServer

安装hMailServer

Configure this hMailServer setting:

配置此 hMailServer 设置:

  1. Open hMailServer Administrator.
  2. Click the "Add domain ..." button to create a new domain.
  3. Under the domain text field, enter your computer's localhost IP.
    • Example: 127.0.0.1 is your localhost IP.
  4. Click the "Save" button.
  5. Now go to Settings > Protocols > SMTP and select the "Delivery of Email" tab.
  6. Find the localhost field enter "localhost".
  7. Click the Save button.
  1. 打开 hMailServer 管理器。
  2. 单击“添加域...”按钮以创建新域。
  3. 在域文本字段下,输入您计算机的本地主机 IP。
    • 示例:127.0.0.1 是您的本地主机 IP。
  4. 单击“保存”按钮。
  5. 现在转到设置 > 协议 > SMTP 并选择“电子邮件传递”选项卡。
  6. 找到 localhost 字段输入“localhost”。
  7. 单击保存按钮。

Configure your Gmail account, perform following modification:

配置您的 Gmail 帐户,进行以下修改:

  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 your Google Mail address in the Username field.
  6. Enter your Google Mail password in the password field.
  7. Check mark "Use SSL"
  8. Save all changes.
  1. 转至设置 > 协议 > SMTP,然后选择“电子邮件传送”选项卡。
  2. 在远程主机名字段中输入“smtp.gmail.com”。
  3. 输入“465”作为端口号。
  4. 选中“服务器需要身份验证”。
  5. 在用户名字段中输入您的 Gmail 地址。
  6. 在密码字段中输入您的 Google Mail 密码。
  7. 勾选“使用 SSL”
  8. 保存所有更改。


Optional

可选的

If you want to send email from another computer you need to allow deliveries from External to External accounts by following steps:

如果您想从另一台计算机发送电子邮件,您需要通过以下步骤允许从外部帐户发送到外部帐户:

  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.
  1. 转到设置 > 高级 > IP 范围,然后双击 IP 地址为 127.0.0.1 的“我的电脑”
  2. 选中允许从外部帐户交付到外部帐户复选框。
  3. 使用保存按钮保存设置。

回答by Anand Singh

For me Fake Sendmailworks.

对我来说,Fake Sendmail有效。

What to do:

该怎么办:

1) Edit C:\wamp\sendmail\sendmail.ini:

1) 编辑 C:\wamp\sendmail\sendmail.ini:

smtp_server=smtp.gmail.com
smtp_port=465
[email protected]
auth_password=your_password

2) Edit php.iniand set sendmail_path

2) 编辑php.ini和设置sendmail_path

sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

That's it. Now you can test a mail.

就是这样。现在您可以测试邮件了。

回答by tchow002

Try using fake sendmail to send emails in a WAMP enviroment.

尝试使用假 sendmail 在 WAMP 环境中发送电子邮件。

http://jesin.tk/using-sendmail-on-windows/

http://jesin.tk/using-sendmail-on-windows/

回答by Mitul Shah

a) Open the "php.ini". For XAMPP,it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMP or LAMP server. Note : Make a backup of php.ini file 

b) Search [mail function] in the php.ini file. 

You can find like below.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25


; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost


Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25. Change sendmail_from from postmaster@localhost to your domain email address which will be used as from address.. 

So for me, it will become like this.
[mail function]
; For Win32 only.
SMTP = smtp.planetghost.com
smtp_port = 25
; For Win32 only.
sendmail_from = [email protected]
auth_username = [email protected]
auth_password = example_password


c) Restart the XAMPP or WAMP(apache server) so that changes will start working.

d) Now try to send the mail using the mail() function , 

mail("[email protected]","Success","Great, Localhost Mail works");

credit

信用

================================================================================

================================================== ==============================

Another way

其它的办法

Gmail servers use SMTP Authentication under SSL. 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 下使用 SMTP 身份验证。我认为在这种情况下无法使用 mail() 函数,因此您可能需要检查以下替代方法:

  1. PEAR: Mail
  2. phpMailer
  1. 梨:邮件
  2. 邮件程序

They both support SMTP auth under SSL.

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

Credit : Check reference answer here

信用:在此处查看参考答案

回答by Khaled Rahman

Here are the steps for send email from localhost by wamp server with Sendmail.

以下是使用 Sendmail 通过 wamp 服务器从本地主机发送电子邮件的步骤。

  1. First, you need to download Sendmail zip file link
  2. Extract the zip file and put it on C:\wamp
  3. Now, you need to edit Sendmail.inion C:\wamp\sendmail\sendmail.ini
  1. 首先,您需要下载Sendmail zip 文件链接
  2. 解压缩 zip 文件并将其放在 C:\wamp
  3. 现在,你需要编辑Sendmail.iniC:\wamp\sendmail\sendmail.ini
smtp_server=smtp.gmail.com 
smtp_port=465
[email protected]
auth_password=your_password
smtp_server=smtp.gmail.com 
smtp_port=465
[email protected]
auth_password=your_password
  1. Access your email account. Click the Gear Tool > Settings > Forwarding and POP/IMAP > IMAP access. Click "Enable IMAP", then save your changes
  2. Run your WAMP Server. Enable ssl_module under Apache Module.
  3. Next, enable php_openssl and php_sockets under PHP.
  4. ** Now the important part open php.inifile on "C:\wamp\bin\php\php5.5.12\php.ini"and "C:\wamp\bin\apache\apache2.4.9\bin\php.ini"set sendmail_path**
  1. 访问您的电子邮件帐户。单击齿轮工具 > 设置 > 转发和 POP/IMAP > IMAP 访问。单击“启用 IMAP”,然后保存更改
  2. 运行您的 WAMP 服务器。在 Apache 模块下启用 ssl_module。
  3. 接下来,在 PHP 下启用 php_openssl 和 php_sockets。
  4. ** 现在重要的部分是打开php.ini文件"C:\wamp\bin\php\php5.5.12\php.ini""C:\wamp\bin\apache\apache2.4.9\bin\php.ini"设置sendmail_path**

sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

  1. Restart Wamp Server.
  1. 重新启动 Wamp 服务器。

It will surely be worked.

它肯定会起作用。

回答by Avdhesh

Without any SMTP server sending mail,use this code for sending mail....

没有任何SMTP服务器发送邮件,使用此代码发送邮件....

click below for mail sending code

Click here

点击这里

listen guys first you can do this less secure your gmail accountafter send mail with your gmail account

先听听大家的意见 您可以在使用您的 Gmail 帐户发送邮件后降低您的 Gmail 帐户的安全性

You can use this php.ini setting

您可以使用此 php.ini 设置

;smtp = smtp.gmail.com
;smtp-port = 25
;sendmail_from = my gmail is here

And sendmail.ini settings

和 sendmail.ini 设置

smtp_server = smtp.gmail.com
smtp_port = 465
smtp_ssl = auto
auth_username = my gmail is here
auth_password = password
hostname = localhost

you can try this changes and i hope this code sent mail....

回答by Hotwire

If you have a wamp setup that won't send emails, there is only a couple of things to do. 1. find out what the smtp server name is for your isp. The gmail thing is most likely unnecessary complication 2. create a phpsetup.php file in your 'www' folder and edit like this:

如果您的 wamp 设置不会发送电子邮件,那么只需要做几件事。1. 找出您的 ISP 的 smtp 服务器名称。gmail 的事情很可能是不必要的并发症 2. 在您的“www”文件夹中创建一个 phpsetup.php 文件并像这样编辑:

<?php
   phpinfo();
?>

this will give you a handle on what wamp is using. 3. search for the php.ini file. there may be serveral. The one you want is the one that effects the output of the file above. 4. find the smtp address in the most likely php.ini. 5. Type in your browser localhost/phpsetup.php and scroll down to smtp setting. it should say 'localhost' 6. edit the php.ini file smtp setting to the name of your ISPs smtp server. check if it changes for you phpsetup.php. if it works your done, if not you are working the wrong file.

这将使您了解 wamp 正在使用的内容。3.搜索php.ini文件。可能有几个。您想要的是影响上述文件输出的那个。4.在最有可能的php.ini中找到smtp地址。5. 在浏览器中输入 localhost/phpsetup.php 并向下滚动到 smtp 设置。它应该显示'localhost' 6. 将 php.ini 文件 smtp 设置编辑为您的 ISP smtp 服务器的名称。检查它是否为您更改 phpsetup.php。如果它有效,你就完成了,否则你正在处理错误的文件。

this issue should be on the Wordpress site but they are way too up-them-selves or trying to get clients.;)

这个问题应该在 Wordpress 网站上,但他们太自私或试图获得客户。;)

回答by Umair

Here is the BESTEST way to send emails using PHPmailer library, this is the only method that works for me.

这是使用 PHPmailer 库发送电子邮件的最佳方式,这是唯一适合我的方法。

require_once 'mailer/class.phpmailer.php';
    $mail = new PHPMailer(); // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->Username = "[email protected]";
    $mail->Password = "xxxxxxx";
    $mail->SetFrom("[email protected]");
    $mail->AddAddress($to);
    $logfile = dirname(dirname(__FILE__)) . '/mail.log';
    try {
        $mail->Body = $message;
        $mail->Subject = $subject;


        file_put_contents($logfile, "Content: \n", FILE_APPEND);
        file_put_contents($logfile, $message . "\n\n", FILE_APPEND);

        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Email has been sent";
        }
    } catch (Exception $e) {
        #print_r($e->getMessage());
        file_put_contents($logfile, "Error: \n", FILE_APPEND);
        file_put_contents($logfile, $e->getMessage() . "\n", FILE_APPEND);
        file_put_contents($logfile, $e->getTraceAsString() . "\n\n", FILE_APPEND);
    }