繁体   English   中英

在Codeigniter中发送电子邮件时出现错误500

[英]Getting an Error 500 when sending an email in Codeigniter

我在使用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');
    }
}

在项目根目录的index.php中将ENVIRONMENT设置为“ development”,然后检查错误日志。

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

表单验证应为

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.";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM