【问题标题】:sending email using codeigniter email class使用 codeigniter 电子邮件类发送电子邮件
【发布时间】:2017-12-07 08:55:25
【问题描述】:

我尝试使用 codeigniter 电子邮件类发送电子邮件时出错。

我有一个错误: 无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 ini_set()

如何测试在 codeigniter 中发送电子邮件?我也在使用本地主机。是不是只有在我使用 localhost 时才会出现这个问题?

这是我的代码:

public function emailme() {
        $this->load->library('email');
        $message = $this->input->post('email_msg');
        $this->email->from('iamjohnx3303@yahoo.com', 'John');
        $this->email->to('iamjohnx3302@gmail.com');
        $this->email->subject('Email Test');
        $this->email->message($message);
        $this->email->send();
    }

【问题讨论】:

标签: php codeigniter email


【解决方案1】:

sendmail.ini中的配置

路径c:\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

路径c:\xampp\xampp\php\php.ini

[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

然后

$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);

XAMPP 中的邮件设置(重要)

$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);

$this->email->send(); //sending mail

【讨论】:

  • 我会试试你的回答先生,并立即回复
  • 另外,将您的 gmail 中的设置更改为允许不太安全的应用访问您的帐户
【解决方案2】:

在发送邮件脚本之前使用它

// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");

// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com');

【讨论】:

  • 有趣!这样保持了php.ini的独创性而不是每次都修改
猜你喜欢
  • 1970-01-01
  • 2013-01-07
  • 2019-08-07
  • 1970-01-01
  • 2012-03-22
  • 2012-12-29
  • 1970-01-01
相关资源
最近更新 更多