【问题标题】:Unable to send email in live server in codeingiter无法在 codeigniter 的实时服务器中发送电子邮件
【发布时间】:2019-07-28 10:30:14
【问题描述】:

Error screentshot Hello guyz 我正在 codeingniter 中发送邮件功能,相同的电子邮件功能在 localhost 中工作,但在实时服务器中不起作用我无法理解这个错误,请帮助我.. 这是我的电子邮件代码:

$config = array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'email', // change it to yours
            'smtp_pass' => 'password', // change it to yours
            'mailtype' => 'html',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE
        );

        $message =  "
        <html>
        <head>
        <title>Verification Code</title>
        </head>
        <body>
        <h2>Thank you for Registering.</h2>
        <p>Your Account:</p>
        <p>Dear: ".$firstname."</p>
        <p>Please click the link below to activate your account.</p>
        <h4><a href='".base_url()."welcome/activate/".$id."/".$code."'>Activate My Account</a></h4>
        </body>
        </html>
        ";

        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        $this->email->from($config['smtp_user']);
        $this->email->to($email);
        $this->email->subject('Signup Verification Email');
        $this->email->message($message);

        //sending email
        if($this->email->send()){
            $this->session->set_flashdata('message','Register Successfull And your Activation link send in Email Please Verify Your Account');
        }
        else{
            $this->session->set_flashdata('message', $this->email->print_debugger());

        }

错误:

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

【问题讨论】:

  • if($this->email->send()) 在此 if 条件之后执行哪个部分...?另外,它是否显示任何错误,如果是,那是什么?
  • 我只是把我的错误截图请检查它@Shujaat sir
  • 好吧,如果您阅读了错误,您会发现问题所在的不是您的代码,而是邮件服务器。 Gmail 实际上拒绝接受发送电子邮件(“验证密码失败请通过您的网络浏览器登录,然后重试”)。您可能使用了错误的 gmail 凭据(请记住,gmail 的传出服务器不允许未经身份验证的发送),或者您可能启用了 2FA 或其他什么。
  • 话虽如此,您应该在端口 465 上使用 (IIRC) 端口 587 和 TLS/StartTLS 而不是 SSL...您网站上显示的相同错误消息指向 this google support resource有关如何进行的更多信息
  • 请将代码和错误作为文本而不是屏幕截图发布。这将最大限度地提高我们为您提供帮助的能力。

标签: php codeigniter email model-view-controller


【解决方案1】:

您显示的错误与您的代码无关,而是它的authentication 错误意味着谷歌服务器不允许您登录。 现在为了运行此代码,请确保您使用了正确的用户名和密码。 之后,您必须从您的 Google/Gmail 帐户中打开“Allow less secure apps”选项。

之后,您的代码应该能够发送电子邮件。

另外,当您将脚本上传到网络主机后,您应该使用您的域名的电子邮件地址,例如support@yourDomain.com,它看起来更专业。

下面的代码是完整的工作代码。在运行它之前,您必须从您的主机面板创建一个电子邮件地址,如admin@yourDomain.com,其中将有一个电子邮件管理选项。

$this->load->library('email');
$encodeEmail = bin2hex('email@gmail.com']);
$this->email->from('admin@yourDomain.com', 'Your Domain');
$this->email->to('email@gmail.com');
$this->email->subject('Email Verification Required');
$url = site_url() . 'verify/' . $data['verification'] . '/' . $encodeEmail;

$message = "";
$message .= "You have signed up with our website \r\n";
$message .= "Please click on given below link to verify and activitate your account. \r\n" . $url;

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

【讨论】:

  • 非常感谢,我会在我的服务器上配置电子邮件。你的回答对我很有帮助
猜你喜欢
  • 1970-01-01
  • 2020-05-09
  • 2014-11-27
  • 2012-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-21
  • 2012-12-05
相关资源
最近更新 更多