使用PHP,LAMPP和PostFix发送邮件

我已经尝试了整整两天,而且我无法获得最简单的工作。

问题:将电子邮件从PHP发送到我的电子邮件地址不起作用

我之前一直在使用WindowsSendmail (Sendmail在XAMPP包中)并且一切正常。 Linux的XAMPP-package(1.7.7)没有集成Sendmail。 所以经过谷歌搜索后我发现Postfix更适合LAMPP环境。


到目前为止我尝试了什么:

我已经安装了Postfix,并希望将其配置为仅使用我的私人电子邮件提供商的smtp-server (就像在Windows上一样)。 所以我像我这样混淆了我的php.ini

[mail function] ; For Win32 only. ;SMTP = localhost ;smtp_port = 25 ; For Win32 only. ;sendmail_from = me@example.com sendmail_path = /etc/postfix mail.add_x_header = On 

请注意,我已经注释掉了“仅限Win32”字样。 /etc/postfix/main.cf看起来像这样:

 smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_password myhostname = ubuntu alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases sender_canonical_maps = hash:/etc/postfix/sender_canonical mydestination = ubuntu, localhost.localdomain, localhost relayhost = mail.gmx.net mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only 

/ etc / aliases不变:

 # Required aliases postmaster: root MAILER-DAEMON: postmaster # Common aliases abuse: postmaster spam: postmaster 

/ etc / postfix / sasl_password

 my.providers.smtp my_login:my_password 

的/ etc / postfic / sender_canonical:

 postmaster my.email@ddress.com 

怎么了:

所以,当我这样做

 > sudo /etc/init.d/postfix start 

一切似乎工作正常, / var / log / mail.log说: “ubuntu postfix / master [9720]:守护进程启动 – 版本2.8.5,配置/ etc / postfix”

但是,当我运行我的PHP脚本(在Windows和Sendmail中运行良好)时,它只是运行并且没有任何反应,甚至没有记录错误。


我真正想要实现的目标:

我在电子商务网站上本地工作。 它在专用的网络服务器上运行良好,但我想让它在本地运行,原因很明显。 在某些情况下,它会发送电子邮件,我只是希望能够使用Thunderbird或其他任何方式接收它们。 在这里使用Postfix overkill? 我不需要接收电子邮件 – 我只想以某种方式显示已发送的邮件。 我似乎找不到任何有用的分步教程来解决这个问题(既不涉及Senmail也不关注Postfix – 但说实话,我对Linux很新)。

在你的php.ini中,这个:

 sendmail_path = /etc/postfix 

应该是sendmail(或兼容)二进制文件的路径。
您已将其设置为postfix的配置目录,这是不对的。

由于历史原因,通常将/usr/bin/sendmail维护为兼容性链接。
sendmail是第一个(我猜),几乎所有东西都假设它在已安装的MTA中。 因此,当它不是时,替换产生符号链接,以便没有任何破坏。

要从localhost(WAMP,XAMP或LAMP)发送邮件,您可以使用PHPMailer包

这将是自述文件中给出的相同指令。

WAMP(窗口):

首先,您必须编辑“php.ini”要查找此文件,请使用WAMP服务器中的以下代码显示phpinfo。 在C:/ wamp / www /中创建一个php文件[setting.php],并将以下内容添加到该文件中。

  

在浏览器中键入localhost / setting.php 。 搜索“加载配置文件”这将是您的php.ini的路径。

php.ini文件中删除给予`extension = php_openssl.dll的;(半冒号)。 现在服务器设置结束了……

  • 从github下载PHPMailer文件夹后,
  • 提取 – >将完整文件夹复制到项目文件夹即C:/ wamp / www /
  • 找到index.php文件。
  • 根据需要更改参数。
  • 然后在浏览器中键入localhost / PHPMailer / index.php
  • 如果发送电子邮件,它将显示成功的消息,否则它将给出错误消息。

LAMP(Linux):

  • 在Linux的情况下,没有必要编辑php.ini文件,因为我在WAMP下解释了第一点。

  • 另一个变化是项目或文档根文件夹是不同的。

  • 在Linux中,默认的Document根文件夹将是/ var / www
  • 您可以轻松更改Document根文件夹。 对于该访问https://stackoverflow.com/a/17612396/1925943
  • 将PhpMailer复制到此文档根文件夹并根据需要编辑index.php。
  • 然后在浏览器中键入localhost / PhpMailer / index.php

要通过Gmail从localhost发送电子邮件(使用sendmail包),请检查PHP + Ubuntu使用gmail格式发送电子邮件localhost可能是另一个答案。