如何从本地WAMP服务器发送电子邮件以发送电子邮件Gmail Hotmail或其他?

23

我正在寻找有关如何从本地主机WAMP发送电子邮件的适当信息。以及如何获得授权,从特定授权电子邮件地址发送任何其他电子邮件地址。

如何配置整个步骤,请详细说明给我,我已经访问了一些 Stack Overflow 答案以及博客文章,但所有这些都非常混乱和过时,所以可能无法正常工作。因此,我需要 Stack Overflow 用户的帮助。谢谢。


1
你无法从本地主机发送电子邮件。这需要SMTP。 - Satish Sharma
8个回答

19

localhost配置一个工作的电子邮件客户端是相当困难的,我花了几个小时的时间尝试它而感到沮丧。最后我找到了这种方法来发送邮件(使用WAMP,XAMPP等):

安装hMailServer

配置此hMailServer设置:

  1. 打开hMailServer管理员。
  2. 点击“添加域...”按钮创建一个新域。
  3. 在域文本字段下,输入计算机的本地主机IP。
    • 例如:127.0.0.1是你的本地主机IP。
  4. 点击"保存"按钮。
  5. 现在转到 设置 > 协议 > SMTP并选择 “电子邮件传递”选项卡。
  6. 在localhost字段中查找并输入“localhost”。
  7. 点击保存按钮。

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

  1. 转到 设置 > 协议 > SMTP 并选择 “电子邮件传递”选项卡。
  2. 在Remote Host name字段中输入“smtp.gmail.com”。
  3. 将端口号输入“465”。
  4. 勾选“服务器需要身份验证”。
  5. 在用户名字段中输入您的Google邮箱地址。
  6. 在密码字段中输入您的Google邮箱密码。
  7. 勾选“使用SSL”。
  8. 保存所有更改。

可选项

如果您想从另一台计算机发送电子邮件,需要按照以下步骤允许来自外部帐户的交付:

  1. 转到 设置 > 高级 > IP范围,并双击“我的计算机”,它应该具有IP地址127.0.0.1。
  2. 选中“允许从外部到外部帐户投递”复选框。
  3. 使用保存按钮保存设置。

1
在配置完成后,我需要知道如何在 PHP 脚本中使用它吗? - 151291
1
但请记住,任何像样的真实邮件服务器都不会接受您的邮件,因为您看起来更像是垃圾邮件发送者,而不是一个明智、高质量的邮件服务器。 - RiggsFolly

10

对于我而言,Fake Sendmail 可以使用。

操作步骤:

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

smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user@gmail.com
auth_password=your_password

2) 编辑 php.ini 文件并设置 sendmail_path

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

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


3

我需要正确的配置步骤。我已经检查了所有的URL。 - Jaykumar Patel
你是什么意思。我认为我提供给你的链接已经解释了所需的步骤。 - tchow002

2
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 = info@planetghost.com
auth_username = example_username@example.com
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("abc@gmail.com","Success","Great, Localhost Mail works");

参考链接

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

另一种方式

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

  1. PEAR: Mail
  2. phpMailer

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

参考来源:请点击此处查看答案


我尝试用这种方式进行配置。 - Jaykumar Patel
你的意思是你已经尝试过了吗? - Mitul Shah
不,目前我按照这个步骤进行配置。 - Jaykumar Patel
auth_username 和 auth_password 不存在,你需要在 php.ini 文件中添加它们的值。 - Mitul Shah

1

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

  1. 首先,您需要下载Sendmail zip文件link
  2. 解压缩zip文件并将其放置在C:\wamp目录下
  3. 现在,您需要编辑C:\wamp\sendmail\sendmail.ini中的Sendmail.ini文件
smtp_server=smtp.gmail.com 
smtp_port=465
auth_username=user@gmail.com
auth_password=your_password
  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"

  1. 重新启动Wamp服务器。

它肯定会起作用。


0
如果您的wamp设置无法发送电子邮件,只需要做几件事情。 1. 找出您的ISP的SMTP服务器名称。Gmail可能是不必要的复杂化。 2. 在您的“www”文件夹中创建一个phpsetup.php文件,并进行编辑,如下所示:
<?php
   phpinfo();
?>

这将使您了解wamp正在使用什么。 3.搜索php.ini文件。可能会有几个。您想要的是影响上面文件输出的文件。 4.在最可能的php.ini中查找smtp地址。 5.在浏览器中键入localhost/phpsetup.php,向下滚动到smtp设置。应该说“localhost”。 6.将php.ini文件smtp设置编辑为您的ISP smtp服务器的名称。 检查它是否对您的phpsetup.php进行更改。如果有效,您完成了,否则您正在处理错误的文件。

这个问题应该出现在WordPress网站上,但他们太自大或试图获取客户;)


0

以下是使用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 = "xxxxxx@gmail.com";
    $mail->Password = "xxxxxxx";
    $mail->SetFrom("xxxx@xxx.com");
    $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);
    }

我在哪里可以下载邮件发送程序?你正在使用哪个邮件发送函数? - 151291
@151291 https://packagist.org/packages/phpmailer/phpmailer - kjdion84

0

在没有SMTP服务器发送邮件的情况下,可以使用此代码来发送邮件....

click below for mail sending code

点击这里

听着,首先你可以降低 Gmail 账户的安全性,然后使用你的 Gmail 账户发送邮件。

你可以使用这个 php.ini 设置。

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

和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....

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接