CodeIgniter + MAMP:无法发送电子邮件

时间:2013-08-12 10:44:12

标签: php codeigniter email mamp

我正在尝试发送带有在MAMP上运行的CI的电子邮件。但它不起作用,我的脚本遇到无限循环,没有任何事情发生...... 我是否需要设置一些特别用于从localhost发送电子邮件的内容?

以下是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';

干杯

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

    $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。不要担心这些问题,我已经检查过我的问题不是由于这些问题。

2 个答案:

答案 0 :(得分:2)

最后我找到了解决方案:

使用MAMP发送电子邮件(mail()PHP函数)

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

  2. 设置后缀:http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/

  3. 进入MAMP的php.ini(浏览phpinfo()以了解使用的版本并得出您需要编辑的文件夹),注释行 SMTP smtp_port sendmail_from 。取消注释 sendmail_path 行并将 / usr / sbin / sendmail -t -i 设置为新值。

  4. 如果PostFix工作正常,你应该能够立即发送电子邮件(在上面的教程中给出运行测试)。

    发送带CI的电子邮件

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

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

        $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值。

答案 1 :(得分:1)

您需要使用sendmaildetails how install it on MAMP)。或者您可以使用下面的解决方案在localhost中存储电子邮件(类似于模拟电子邮件发送)。 我在我的localhost(XAMPP)上使用此解决方案。也许它会对你有所帮助。

php.ini

中指定发送邮件的路径
sendmail_path = "path/to/php path/to/sendmail.php"

第二步 - 您可以尝试使用此脚本

    define('DIR','path/to/sendmail_dir');
    $stream = '';
    $fp = fopen('php://stdin','r');
    while($t = fread($fp,2048)){
        if($t === chr(0)){
            break;
        }
        $stream .= $t;
    }
    fclose($fp);

    $fp = fopen(mkname(),'w');
    fwrite($fp,$stream);
    fclose($fp);

    function mkname($i=0){
       $fn = DIR.date('Y-m-d_H-i-s_').$i.'.eml';
       if (file_exists($fn)){
           return mkname(++$i);
       }   
       else{
           return $fn;
       }
   }
相关问题