4

我正在按照教程使用 gmail 发送电子邮件,但是我得到的是一个页面,它只是挂起,甚至没有加载错误。我正在使用 MAMP,所以这可能是它不起作用的原因。

class Email extends CI_Controller{

    public function __construct()
   {
        parent::__construct();

   }

    function index(){

        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'email',
            'smtp_pass' => 'pass'
        );

        $this->load->library('email',$config);

        $this->email->set_newline("/r/n");
        $this->email->from('email', 'George');
        $this->email->to('email');
        $this->email->subject('hey this is an email');
        $this->email->message('this is the content of the email');

        if($this->email->send()){

                echo 'Your message was sent';

        }else{

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

        }

    }



}
4

5 回答 5

7

在您的 php.ini 文件中取消注释 extension=php_openssl.dll

$config = Array(
            'protocol'  => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => '465',
            'smtp_user' => 'someuser@gmail.com',
            'smtp_pass' => 'password',
            'mailtype'  => 'html',
            'starttls'  => true,
            'newline'   => "\r\n"
        );

    $this->load->library('email', config);
    $this->email->from('email@gmail.com', 'George');
    $this->email->to('email@gmail.com');
    $this->email->subject('hey this is an email');
    $this->email->message('this is the content of the email');
    $this->email->send();
    echo $this->email->print_debugger();

希望这会奏效

于 2012-05-14T17:15:57.813 回答
0

导致问题的行是:

$this->email->set_newline("/r/n");

删除它并尝试发送电子邮件。

于 2012-05-14T15:17:12.260 回答
0

我自己只是成功地做到了这一点,但是通过发送 config/email.php 中的所有值来代替。那部分应该无关紧要。

好吧,基本上你是想通过@gmail 帐户还是你自己的域发送?如果您尝试通过自己的域,则需要将 DNS 更改为相关的 google 设置:

创建 MX 记录

于 2012-05-14T19:14:17.990 回答
0

MAMP 不附带 openssl 扩展,但您可以自己创建它。有关详细信息,请参阅教程

于 2013-08-02T11:55:22.480 回答
-1

首先使用标准 smtp 端口发布,并确保使用以下配置工作:

  函数索引(){

        $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'smtp.googlemail.com', 'smtp_port' => 25, 'smtp_user' => 'email', 'smtp_pass' => 'pass ');

        $this->load->library('email',$config);

        $this->email->from('email', 'George'); $this->email->to('email'); $this->email->subject('嘿,这是一封电子邮件'); $this->email->message('这是邮件内容');

        $this->email->send(); }

一旦你尝试过并且一切正常,请阅读以下内容:

http://codeigniter.com/forums/viewthread/84689/

于 2012-05-15T07:35:08.097 回答