【问题标题】:How can I get fix this error of this email issue with codeigniter? [duplicate]如何使用 codeigniter 修复此电子邮件问题的错误? [复制]
【发布时间】:2018-07-23 08:23:42
【问题描述】:

我有这样的问题。我想从我的网络应用程序发送邮件,所以我把它放在我的控制器中。

$from_email = "tharuwan40@gmail.com";
$to_email = "warimali94@gmail.com";

//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Info');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

这个 Web 应用程序仍在本地主机上运行。我在网上尝试了很多示例,这些示例也已在堆栈溢出中发布。但我的邮件上没有任何内容。电子邮件未发送。我该如何解决这个问题?

【问题讨论】:

  • 您是否正确设置了首选项? codeigniter.com/userguide2/libraries/email.html
  • 检查 $this->email->send() 返回 true 还是 false。也尝试通过 codeigniter 使用 print_debugger()。
  • 在localhost中,你是使用smtp还是安装sendmail?
  • 我正在使用 smtp
  • $this->email->send() this return false

标签: php codeigniter email


【解决方案1】:

创建配置数组

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

然后

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

  $this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
  $this->email->to('target@gmail.com'); //receiver mail

  $this->email->subject('testing');
  $this->email->message($message);

  if($this->email->send()) //sending mail
  {
     echo 'Mail sent';
  }
  else
  { 
     print_r($this->email->print_debugger(), true);
  }

sendmail.ini 中的配置

路径 [xampp 文件夹]\sendmail\sendmail.ini

配置

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com

打开php.ini配置文件并搜索[邮件功能]

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

重启服务器

Main Source

【讨论】:

  • 是 smtp_pass 我的电子邮件密码吗?
  • 无法使用 PHP mail() 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。日期:2018 年 2 月 13 日星期二 05:22:38 +0100 来自:“Tharindu” 返回路径: 回复: 用户-代理:CodeIgniter X-Sender:tharindusandaruwan40@gmail.com X-Mailer:CodeIgniter X-Priority:3(正常) Message-ID: Mime-Version:1.0 Content-Type:text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit =?UTF-8?Q?testing?= test
  • 它给了我这样的感觉
  • 我已经修改了我的代码。请尝试以上配置更改。
猜你喜欢
  • 1970-01-01
  • 2019-09-08
  • 2011-08-13
  • 2023-03-11
  • 2019-11-21
  • 1970-01-01
  • 2015-06-08
  • 2011-06-12
  • 1970-01-01
相关资源
最近更新 更多