【问题标题】:Send e-mail with Codeigniter 3.0.3 via SMTP通过 SMTP 使用 Codeigniter 3.0.3 发送电子邮件
【发布时间】:2016-04-16 06:41:42
【问题描述】:

我的email.php 位于config/ 文件夹中:

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'gmfernandes@[domain].com';
$config['smtp_pass'] = '[password]';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";

我的email() 方法:

public function email()
{
    $from_name = $this->input->post('nome_email');
    $from_email = $this->input->post('email_email');
    $to = 'gmfernandes@[domain].com';
    $subject = 'Testing';
    $message = $this->input->post('proposta_email');

    $this->email->from($from_email, $from_name);
    $this->email->to($to);
    $this->email->subject($subject);
    $this->email->message($message);

    if ($this->email->send()) {
        echo 'Sent!';
    } else {
        echo $this->email->print_debugger();
    }

    die;
}

我的autoload.php

$autoload['libraries'] = array('database', 'session', 'form_validation', 'email');

我正在努力完成这项工作。我花了几个小时寻找解决方案,但没有一个能帮助我。多次删除并安装sendmailpostfix,尝试使用默认配置但没有。它对我不起作用。

现在,显示的消息:

hello: F

The following SMTP error was encountered: F
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Mon, 11 Jan 2016 18:11:54 -0200
From: "Gabriel" <mfgabriel@[domain].com>
Return-Path: <mfgabriel@[domain].com>
To: gmfernandes@[domain].com
Subject: =?UTF-8?Q?Testing?=
Reply-To: "mfgabriel@[domain].com" <mfgabriel@[domain].com>
X-Sender: mfgabriel@[domain].com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <56940c8a3846e@[domain].com>
Mime-Version: 1.0

Content-Type: multipart/alternative; boundary="B_ALT_56940c8a384c8"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_56940c8a384c8
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Teste


--B_ALT_56940c8a384c8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Teste

--B_ALT_56940c8a384c8--

怎么办?

编辑#1

将我的config.php 文件更改为ssl://smtp.gmail.com 后,显示了一条新的更大的错误消息。以上User Agent: CodeIgniter

220 smtp.gmail.com ESMTP g130sm55276890qkb.28 - gsmtp

hello: 250-smtp.gmail.com at your service, [2804:14d:2c81:17a2:f82f:e7e9:68ec:6230]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

Failed to authenticate password. Error: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 g130sm55276890qkb.28 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

【问题讨论】:

  • @GabrieIMF 在我的回答中尝试使用ssl://smtp.googlemail.com

标签: php codeigniter email ubuntu smtp


【解决方案1】:

您使用端口 465,即 SSL。

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

【讨论】:

    【解决方案2】:

    完成。有效。我必须在“我的帐户”>“登录和安全配置”中允许来自不太安全的应用程序的访问,并按照 Schellingerht 所说的去做。

    【讨论】:

      【解决方案3】:

      尝试使用ssl://smtp.googlemail.com 而不是smtp.gmail.com

      $config = array(
          'protocol' => 'smtp',
          'smtp_host' => 'ssl://smtp.googlemail.com',
          'smtp_port' => 465,
          'smtp_user' => 'xxx',
          'smtp_pass' => 'xxx',
          'mailtype'  => 'html', 
          'charset'   => 'iso-8859-1'
      );
      
      $this->load->library('email', $config);
      
      $this->email->from('your@example.com', 'Your Name');
      $this->email->to('someone@example.com');
      
      $this->email->subject('Email Test');
      $this->email->message('Testing the email class.');
      
      $this->email->send();
      

      【讨论】:

        【解决方案4】:
        function Email()
        {
                parent::Controller();   
                    $this->load->library('email');
        }
        
        function index()
        {
            $config['protocol']    = 'smtp';
            $config['smtp_host']    = 'ssl://smtp.gmail.com';
            $config['smtp_port']    = '465';
            $config['smtp_timeout'] = '7';
            $config['smtp_user']    = 'mygmail@gmail.com';
            $config['smtp_pass']    = '*******';
            $config['charset']    = 'utf-8';
            $config['newline']    = "\r\n";
            $config['mailtype'] = 'text'; // or html
            $config['validation'] = TRUE; // bool whether to validate email or not      
        
            $this->email->initialize($config);
        
        
            $this->email->from('mygmail@gmail.com', 'myname');
            $this->email->to('target@gmail.com'); 
        
            $this->email->subject('Email Test');
            $this->email->message('Testing the email class.');  
        
            $this->email->send();
        
            echo $this->email->print_debugger();
        
             $this->load->view('email_view');
        
           }
        

        查看论坛:Sending email with gmail smtp with codeigniter email library

        查看这个答案:Sending email Codeigniter Error

        【讨论】:

          猜你喜欢
          • 2015-11-10
          • 2014-10-15
          • 1970-01-01
          • 2018-03-23
          • 2011-04-06
          • 2017-05-12
          • 2011-10-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多