无法从CodeIgniter发送电子邮件

时间:2017-09-12 01:53:47

标签: codeigniter email

我正在使用CodeIgniter v3.1.4。在我的网站上,我有一个“联系我们”页面,其电子邮件发送功能根本不起作用。最奇怪的是,确切的代码在我的另一个项目中完美运行它不在这个项目中。

$this->email->send() 

以上行执行但不发送任何电子邮件。它也没有显示任何错误消息。但是,如果'来自'地址& 'to'地址与(info@mywebsite.org)相同,然后它会发送邮件给自己。当'from'地址就像(user@gmail.com),'to'地址就像(info@mywebsite.org) ),它不起作用。

我用来发送电子邮件的代码是:

$this->form_validation->set_rules('sender_name', 'Name', 'required');
$this->form_validation->set_rules('sender_email', 'Enter Email', 'required|valid_email');
$this->form_validation->set_rules('mail_subject', 'Subject', 'required');
$this->form_validation->set_rules('mail_message', 'Your Message', 'required');

if (isset($_POST) && !empty($_POST))
{
    if ($this->form_validation->run() == TRUE)
    {
        $this->email->from($this->input->post('sender_email'), $this->input->post('sender_name'));
        $this->email->to("info@mywebsite.org");
        $this->email->subject($this->input->post('mail_subject'));
        $this->email->message($this->input->post('mail_message'));

        if($this->email->send()){
            $this->session->set_flashdata('success', 'Thanks for writing to us.You would hear from us shortly.');
        }
        else
        {
            $this->session->set_flashdata('error', 'Your message could not be sent.');
        }
    }
}

我尝试在StackOverflow中实现其他解决方案,但它们都没有工作。请帮助我。

1 个答案:

答案 0 :(得分:0)

首先检查静态数据

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

$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();
echo "<pre>status<br>"print_r($this->email->print_debugger());die;
相关问题