簡體   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