在Codeigniter

时间:2016-06-26 17:11:33

标签: php codeigniter email

我遇到CodeIgniter问题。我已预加载电子邮件配置,但当我尝试使用控制器中的函数发送电子邮件时,我收到错误500.不确定它是什么。请帮忙!

public function regvalidation()
{
    $this->load->library('form_validation');

    $this->form_validation->set_rules('email','email','required|trim|valid_email|is_unique[user_admin.username]');

    $this->form_validation->set_rules('password','Password','required|trim');
    $this->form_validation->set_rules('c_password','Confirm Password','required|trim|matches[password]');


    if ($this->form_validation->run())
    {

        $this->load->library('email');
        $key = md5(uniqueid());

        //echo $this->input->post('email');

        $this->email->from('edgemaster@edge.xyz','Edge Master');
        $this->email->to($this->input->post('email'));
        $this->email->subject("EDGE | Confirm your account");

        $message = "<p>Thank you for signing up</p>";
        $message .= "<p><a href='".base_url()."main/register_user/".$key.">Click here</a>to confirm your account.</p>";

        $this->email->message($message);

        $this->email->send();

        if ($this->email->send())
        {
            echo "This email has been sent.";
        }
        else
        {
            echo "failed.";
        }
    }

    else
    {
        $this->load->view('signup.php');
    }
}

2 个答案:

答案 0 :(得分:2)

将环境设置为&#39; development&#39;在项目根目录下的index.php中,然后检查错误日志。

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(-1);
        ini_set('display_errors', 1);
    break;
...

答案 1 :(得分:0)

表格验证应为

if ($this->form_validation->run() == FALSE)

缺少href属性

上的单引号
$message .= "<p><a href='".base_url()."main/register_user/".$key.">Click here</a>to confirm your account.</p>";
                        ^                                         ^ 

应该是

$message .= "<p><a href='".base_url()."main/register_user/".$key."'>Click here</a>to confirm your account.</p>";

删除电子邮件地址中的第一个email->send()

# remove this
# $this->email->send();

if ($this->email->send())
{
    echo "This email has been sent.";
}
else
{
    echo "failed.";
}