遇到SMTP错误:555 5.5.2语法错误。 u68sm14091815iou.0 - gsmtp

时间:2018-03-08 12:25:37

标签: php codeigniter email

当我回复我的查询消息时,我收到此错误

  

220 smtp.googlemail.com ESMTP u68sm14091815iou.0 - gsmtp

     

你好:250-smtp.googlemail.com为您服务,[122.52.95.242]   250-SIZE 35882577 250-8BITMIME 250-AUTH登录平台XOAUTH2   PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES   250-PIPELINING 250-CHUNKING 250 SMTPUTF8 from:250 2.1.0 OK   u68sm14091815iou.0 - gsmtp to:555 5.5.2语法错误。   u68sm14091815iou.0 - gsmtp遇到以下SMTP错误:   555 5.5.2语法错误。 u68sm14091815iou.0 - gsmtp退出:221 2.0.0   关闭连接u68sm14091815iou.0 - gsmtp无法发送电子邮件   使用PHP SMTP。您的服务器可能未配置为使用发送邮件   这种方法。日期:星期四,2018年3月8日13:19:44 +0100来自:    回程路径:主题:   =?ISO-8859-1] Q = 43 = 65 = 62 = 75 = 20 = 48 = 65 = 72 = 62 = 73 = 20 = 49 = 6E = 71 = 75 = 69 = 72 = 69 = 65 =   =?ISO-8859-1?Q?= 73?=回复:用户代理:CodeIgniter X-Sender:cebuherbs1@gmail.com X-Mailer:CodeIgniter   X-Priority:3(正常)消息ID:< 5aa12a60a8321@gmail.com>   哑剧版:1.0

     

内容类型:multipart / alternative;边界=" B_ALT_5aa12a60a832d"

     

这是MIME格式的多部分邮件。您的电邮申请表   可能不支持这种格式。

     

- B_ALT_5aa12a60a832d Content-Type:text / plain; charset = ISO-8859-1 Content-Transfer-Encoding:8bit

     

asgfdgfdgdf

这是我的控制器

public function reply_inquiries()
    {
          $config = Array(
          'protocol' => 'smtp',
          'smtp_host' => 'ssl://smtp.googlemail.com',
          'smtp_port' => 465,
          'smtp_user' => '*******@gmail.com',
          'smtp_pass' => '********',
          'mailtype' => 'html',
          'charset' => 'iso-8859-1',
          'wordwrap' => TRUE
        );

        $message = $this->input->post('message');
          $this->load->library('email', $config);
          $this->email->set_newline("\r\n");
          $this->email->from('********@gmail.com');
          $this->email->to($this->input->post('email'));
          $this->email->subject('Cebu Herbs Inquiries');
          $this->email->message($message);
          if($this->email->send())
     {
      echo 'Email sent.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }


    }

我的观点

<?php echo form_open('admin/reply_inquiries',['class'=>'col s8']);?>
 <div id="page-wrapper" >
      <div class="header"> 
                        <h1 class="page-header">
                             Reply Inquiries
                        </h1>
            <ol class="breadcrumb">
            <li><a href="<?php echo base_url('admin'); ?>">Home</a></li>
            <li><a href="<?php echo base_url('admin/inquiries_view'); ?>">Inquiries</a></li>
            <li class="active">Reply Inquiries</li>
          </ol> 

    </div>
    <div id="page-inner"> 
       <div class="row">
       <div class="col-lg-12">
       <div class="card">
                        <div class="card-action">
                            Reply
                        </div>
                        <div class="card-content">
      <div class="row">
        <div class="input-field col s4">
          <i class="material-icons prefix">email</i>
          <input name="product_name" type="text" class="validate">
          <label for="email">E-mail</label>
        </div>
        </div>
      <form class="col s6">
                <div class="row">
                <div class="input-field col s4">
                  <i class="material-icons prefix">mode_edit</i>
                  <textarea name="message" class="materialize-textarea"></textarea>
                  <label for="message">Message</label>
                </div>
                </div>
              </form>
      <div class="row">
      <div class="col s4">
            <div class="col-md-10 col-md-offset-2">
        <button type="submit" class="btn btn-success">Reply
        <i class="material-icons right">send</i>
        </button> 
        </div>
      </div>
      </div>
    <?php echo form_close(); ?>
  </div>
    </div>
 </div> 
   </div> 

1 个答案:

答案 0 :(得分:0)

在 Codeiniter4 中,您可以使用配置文件 (app/config/Email.php) 来解决此问题。就我而言,当我尝试将邮件设置为 codeiniter3 或 native 时,我得到了相同的答案。

注意 setTo 和 setFrom

所以转到 app/config/Email.php 并像这样设置:

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{
/**
 * @var string
 */
public $fromEmail;

/**
 * @var string
 */
public $fromName;

/**
 * @var string
 */
public $recipients;

/**
 * The "user agent"
 *
 * @var string
 */
public $userAgent = 'CodeIgniter';

/**
 * The mail sending protocol: mail, sendmail, smtp
 *
 * @var string
 */
public $protocol = 'smtp';

/**
 * The server path to Sendmail.
 *
 * @var string
 */
public $mailPath = '/usr/sbin/sendmail';

/**
 * SMTP Server Address
 *
 * @var string
 */
public $SMTPHost = 'smtp.googlemail.com';

/**
 * SMTP Username
 *
 * @var string
 */
public $SMTPUser = 'myemail@gmail.com';

/**
 * SMTP Password
 *
 * @var string
 */
public $SMTPPass = 'pass**';

/**
 * SMTP Port
 *
 * @var integer
 */
public $SMTPPort = 465;

/**
 * SMTP Timeout (in seconds)
 *
 * @var integer
 */
public $SMTPTimeout = 60;

/**
 * Enable persistent SMTP connections
 *
 * @var boolean
 */
public $SMTPKeepAlive = false;

/**
 * SMTP Encryption. Either tls or ssl
 *
 * @var string
 */
public $SMTPCrypto = 'ssl';

/**
 * Enable word-wrap
 *
 * @var boolean
 */
public $wordWrap = true;

/**
 * Character count to wrap at
 *
 * @var integer
 */
public $wrapChars = 76;

/**
 * Type of mail, either 'text' or 'html'
 *
 * @var string
 */
public $mailType = 'html';

/**
 * Character set (utf-8, iso-8859-1, etc.)
 *
 * @var string
 */
public $charset = 'UTF-8';

/**
 * Whether to validate the email address
 *
 * @var boolean
 */
public $validate = false;

/**
 * Email Priority. 1 = highest. 5 = lowest. 3 = normal
 *
 * @var integer
 */
public $priority = 3;

/**
 * Newline character. (Use “\r\n” to comply with RFC 822)
 *
 * @var string
 */
public $CRLF = "\r\n";

/**
 * Newline character. (Use “\r\n” to comply with RFC 822)
 *
 * @var string
 */
public $newline = "\r\n";

/**
 * Enable BCC Batch Mode.
 *
 * @var boolean
 */
public $BCCBatchMode = false;

/**
 * Number of emails in each BCC batch
 *
 * @var integer
 */
public $BCCBatchSize = 200;

/**
 * Enable notify message from server
 *
 * @var boolean
 */
public $DSN = false;

}

现在,转到您的行代码并获得如下内容:

$email_user = 'myemail@gmail.com;
$message_html = '<h1>Hello solution</h1>';

$to = $email_user;
$subject = 'this is it';
$message = $message_html;
$email = \Config\Services::email();
$email->setTo($to);
$email->setFrom('myemail@gmail.com', 'Hey! here is the solution');
$email->setSubject($subject);
$email->setMessage($message);
if ($email->send()) 
{
    echo 'Email successfully sent';
} 
else 
{
    $data = $email->printDebugger(['headers']);
    print_r($data);
}