CodeIgniter + MAMP:无法发送电子邮件 [英] CodeIgniter + MAMP : unable to send emails

查看:125
本文介绍了CodeIgniter + MAMP:无法发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在MAMP上免费运行的CI发送电子邮件.但这不起作用,我的脚本遇到了无限循环,什么也没发生... 我是否需要进行一些设置,特别是从本地主机发送电子邮件?

I am trying to send emails with CI running on MAMP free. But it doesn't work, my script is encountering an infinite loop and nothing is happening... Do i need to set up something especially to send emails from localhost?

这是我的配置项电子邮件配置:

Here is my email config for CI:

    $config = array();
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.googlemail.com';
    $config['smtp_port'] = 465;
    $config['smtp_user'] = '*****@gmail.com';
    $config['smtp_pass'] = '******';
    $config['mailtype'] = 'html';
    $config['charset']  = 'utf-8';
    $config['newline']  = '\r\n';

欢呼

这是我发送电子邮件的代码:

Here is my code to send an email:

    $config = array();
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.googlemail.com';
    $config['smtp_port'] = 465;
    $config['smtp_user'] = '****';
    $config['smtp_pass'] = '*****';
    $config['mailtype'] = 'html';
    $config['charset']  = 'utf-8';
    $config['newline']  = '\r\n';

    $this->email->initialize($config);

    $this->email->from('****');
    $this->email->to($email);
    $this->email->subject($title);
    $this->email->message($content);

    $this->email->send();

    error_log($this->email->print_debugger());

在脚本的另一部分中定义了$ title,$ content和$ email vars.不用担心这些东西,我已经检查过我的问题不是由于这些原因造成的.

With $title, $content and $email vars defined in another part of my script. Don't worry about this stuff, I've already checked that my issue is not due to these.

推荐答案

最后我找到了解决方法:

Finally I found the solution:

发送带有MAMP的电子邮件(mail()PHP函数)

  1. 设置SSL: http://soundsplausible.com/2012/01/14/enable-ssl-in-mamp-2-0-5/

设置后缀:进入MAMP的php.ini(浏览phpinfo()可以知道使用哪个版本并确定要编辑的文件夹),并在注释行 SMTP smtp_port 发送邮件.取消注释行 sendmail_path ,并将/usr/sbin/sendmail -t -i 设置为新值.

Into MAMP's php.ini (glance phpinfo() to know which version is used and conclude into which folder you need to edit), comment lines SMTP, smtp_port and sendmail_from. Uncomment line sendmail_path and set /usr/sbin/sendmail -t -i as new value.

如果PostFix正常运行,您应该现在就可以发送电子邮件(运行上面教程中给出的测试).

You should be able to send emails now, if PostFix works fine (run test given in tutorial above).

使用CI发送电子邮件

要使用CI发送电子邮件,您无需将登录信息写入PostFix文件中.但是,您需要能够运行PostFix和SSL.

To send emails with CI, you don't need to write your logins into a file for PostFix. However, you need to be able to run PostFix and SSL.

以下是Google帐户的配置文件示例:

Here is an example of config file for a google account:

    $config['protocol'] = "smtp";
    $config['smtp_host'] = "smtp.gmail.com";
    $config['smtp_port'] = "587";
    $config['smtp_user'] = "*****";
    $config['smtp_pass'] = "*****";
    $config['smtp_crypto'] = "tls"; //very important line, don't remove it
    $config['smtp_timeout'] = "5"; //google hint
    $config['mailtype'] = "text";
    $config['charset']  = "utf-8";
    $config['newline'] = "\r\n";

请谨慎使用必要的",否则"可能会引起问题.在这里,我正在使用TLS连接.如果您喜欢SSL,请使用端口465并正确修复smtp_crypto值.

Be careful with " " which are necessary, ' ' could create issues. Here I'm using a TLS connection. If you prefer SSL, use port 465 and fix correctly smtp_crypto value.

这篇关于CodeIgniter + MAMP:无法发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆