使用CodeIgniter通过'mail'或'sendmail'发送电子邮件

3

我建立了一个内部网站应用程序,需要发送电子邮件(低频率)。我将无法使用组织的SMTP服务器,因此需要通过sendmailmail发送这些电子邮件。

然而,当我配置我的电子邮件时:

$config['protocol'] = 'sendmail';

我收到:

Exit status code: 127
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.

当我使用以下代码时:

$config['protocol'] = 'mail';

我理解为:

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

我需要在PHP中设置或检查phpinfo()以确定如何使其工作吗?


1
你尝试过不配置任何东西吗?这种方法大多数情况下都有效。如果这不起作用,那么问题可能在 $config['mailpath'] 变量中。 - Robert
在Google上搜索“codeigniter email settings site:stackoverflow.com”,看看是否有现有的问题/答案可以帮助您。 - Kinjal Dixit
我一直在寻找解决方案,但目前还没有具体的 - 我只需要发送电子邮件,而我找到的所有内容都建议构建一个可以发送和接收电子邮件的电子邮件服务器。 - pepe
2个回答

10

好的 - 这很简单。

对于任何遇到这个问题的人:

  1. 首先检查是否安装了sendmail(实际上是Postfix)。我使用的是Ubuntu 11.x。

cd usr/sbin/

  1. 如果找不到sendmail,则需要安装
sudo apt-get install postfix
我接受了对话框上的默认选项,一旦安装完成,发送电子邮件就没有问题了。

1
在Windows操作系统中,我尝试使用sendmail类。
您需要将sendmail.exe、sendmail.ini和其他两个.dll文件放入以下位置:C:\wamp\sendmail。
为了使用Gmail服务器,需要按照以下方式配置sendmail.ini文件:
[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log
debug_logfile=debug.log
auth_username=mymail@gmail.com
auth_password=mypassword
hostname=smtp.gmail.com

然后编辑您的php.ini文件,该文件位于内部

C:\wamp\bin\apache\Apache2.2.17\bin

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

现在运行您的项目,在以下位置查看日志文件:

C:\wamp\sendmail\error.log C:\wamp\sendmail\debug.log

我认为这篇文章可以帮助您。

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