使用Gmail发送电子邮件不起作用|点火枪

时间:2018-11-06 11:21:12

标签: codeigniter gmail

这是我的代码,用于通过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")


                 }

            });

});

2 个答案:

答案 0 :(得分:0)

尝试一下。...

  

$ 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 ['validation'] = TRUE; // bool是否验证电子邮件

     

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

     

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

     

$ this-> email-> subject('Email Test');

     

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

     

$ this-> email-> send();

     

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

答案 1 :(得分:-1)

  1. 从站点配置文件(yourproject / config / config.php)(例如,
  2. )中检查并设置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;
    }
    }