简体   繁体   中英

Getting an Error 500 when sending an email in Codeigniter

I am having trouble with CodeIgniter. I have preloaded the email configuration but when I try to send an email using a function in the controller, I get an error 500. Not sure what it is. Please help!

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');
    }
}

Set ENVIRONMENT to 'development' in index.php on project root then check for error log.

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

Form validation should be

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

Missing Single quote on the href attribute

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

should be

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

Remove first email->send() in your email code

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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