Sending email with CodeIgniter using 'mail'

2019-04-11 16:29发布

问题:

I built an intranet app that needs to send email (low volume). I will not be able to use the SMTP server of my organization, so I need to send these emails via sendmail or mail.

However, when I config my email as:

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

I get:

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.

and when I use:

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

I get:

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

Is there anything I should setup in PHP or check in phpinfo() to figure out how to get this to work?

回答1:

OK - this was simple.

For anyone who faces this issue:

  1. First check if sendmail (actually Postfix) is installed. I am using Ubuntu 11.x.

cd usr/sbin/

  1. If you can't find sendmail, then it needs to be installed
sudo apt-get install postfix
  1. I accepted the default options on the dialogs and once install was complete, emails sent without a problem.


回答2:

In windows os , i have tried sendmail class.
You have to put sendmail.exe,sendmail.ini, and other two .dll files inside,

C:\wamp\sendmail

configure sendmail.ini file as follow for gmail server :

[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

then edit your php.ini file, that is available inside

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

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

Now run your project, see log files at:

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

i think this post can help you..