【问题标题】:Send email with Gmail not work | codeigniter使用 Gmail 发送电子邮件不起作用 |代码点火器
【发布时间】:2018-11-07 14:52:04
【问题描述】:

这是我用 gmail 发送电子邮件的代码,但它不起作用,我努力让它工作 4 天但仍然不起作用。

请帮帮我,6天前就可以了,之后就不行了,服务器告诉我把PHPMailer改成SMTP Gmail,我改了还是不行……

我在 Amazon SES 电子邮件中注册,但我不知道如何使用它,所以我有 2 个选择:让它在我的普通服务器上运行或更改为 Amazon SES,如果 SES 有更好的机会学习我如何使用它 。

my site to test

我的控制器

 public function Send_Single_Email_Try ()
 {

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

    $this->load->library('email', $email_config);
    $this->email->from('someuser@gmail.com', 'invoice');
    $this->email->to('test@test.com');
    $this->email->subject('Invoice');
    $this->email->message('Test');

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

                echo 1;
            }
            else
            {
                echo 0;

            }
}

我的 JS

   $(document).on('click','#SendEmailTry',function(e){
            e.preventDefault();

         $.ajax({

        url:"<?php echo 
  base_url('Email/Send_Single_Email_Try/')?>",

        type: "POST",
        dataType: "text",

        success:function(data)
                  {
                     if (data == 1)
                      {
                        alert("send");
                      }
                      else
                      {
                         alert("notsend");
                      }


                  },
                    error: function (jqXHR, textStatus, errorThrown)
                 {

                          alert("error")


                 }

            });

});

【问题讨论】:

    标签: codeigniter gmail


    【解决方案1】:

    试试这个....

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

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

    $config['smtp_host'] = 'ssl://smtp.gmail.com';

    $config['smtp_port'] = '465';

    $config['smtp_timeout'] = '7';

    $config['smtp_user'] = 'sender_mailid@gmail.com';

    $config['smtp_pass'] = '密码';

    $config['charset'] = 'utf-8';

    $config['newline'] = "\r\n";

    $config['mailtype'] = '文本'; // 或 html

    $config['验证'] = TRUE; // bool 是否验证电子邮件

    $this->email->初始化($config);

    $this->email->from('sender_mailid@gmail.com', 'sender_name'); $this->email->to('recipient@gmail.com');

    $this->email->subject('电子邮件测试');

    $this->email->message('正在测试电子邮件类。');

    $this->email->send();

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

    【讨论】:

    【解决方案2】:
    1. 从您的站点配置文件(yourproject/config/config.php)检查并设置您的 csrf 保护,例如,

    $config['csrf_protection'] = FALSE;

    1. 你的重写代码:

      public function Send_Single_Email_Try ()    
      {
      $this->output->enable_profiler(FALSE);    
      $email_config = Array(    
      'protocol'  => 'smtp',    
      'smtp_host' => 'ssl://smtp.googlemail.com',    
      'smtp_port' => '465',    
      'smtp_user' => 'xx@gmail.com',    
      'smtp_pass' => 'xx',    
      'mailtype'  => 'html',    
      'starttls'  => true,    
      'newline'   => "\r\n"    
      );
      
      $this->load->library('email', $email_config);
      $this->email->from('someuser@gmail.com', 'invoice');
      $this->email->to('test@test.com');
      $this->email->subject('Invoice');
      $this->email->message('Test');
      
      $send = $this->email->send();
      if($send)
      { 
      
      echo 1;
      }
      else
      {
      echo 0;
      }
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 2015-07-12
      • 2011-09-26
      • 2013-01-22
      • 2016-10-22
      相关资源
      最近更新 更多