亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法在 CodeIgniter 4 中發送服務器電子郵件

無法在 CodeIgniter 4 中發送服務器電子郵件

PHP
汪汪一只貓 2023-04-28 15:59:56
我只是掛斷電話發送服務器電子郵件。我正在準備這樣的電子郵件發送代碼:$email_config = Array(    'charset' => 'utf-8',    'mailType' => 'html');$email = \Config\Services::email();$email->initialize($email_config);$email->setNewline("\r\n");$email->setCRLF("\r\n");$email->setFrom("[email protected]", "Sender name");$email->setTo("[email protected]");$email->setSubject("Test message");$email->setMessage("Hello");if ($email->send()) {    echo "Email sent!";} else {    echo $email->printDebugger();    return false;}它顯示此錯誤消息:Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.Date: Thu, 4 Jun 2020 05:21:47 -0500From: "Sender name" <[email protected]>Return-Path: <[email protected]>Reply-To: <[email protected]>User-Agent: CodeIgniterX-Sender: [email protected]: CodeIgniterX-Priority: 3 (Normal)Message-ID: <[email protected]>Mime-Version: 1.0Content-Type: multipart/alternative; boundary="B_ALT_5ed8cb3ba9e702.65790334"=?UTF-8?Q?Test=20message?=This is a multi-part message in MIME format.Your email application may not support this format.--B_ALT_5ed8cb3ba9e702.65790334Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: 8bitHello--B_ALT_5ed8cb3ba9e702.65790334Content-Type: text/html; charset=UTF-8Content-Transfer-Encoding: quoted-printableHello--B_ALT_5ed8cb3ba9e702.65790334--并在錯誤日志中給出錯誤:Email: sendWithMail throwed Use of undefined constant INTL_IDNA_VARIANT_UTS46 - assumed 'INTL_IDNA_VARIANT_UTS46' (this will throw an Error in a future version of PHP)我想提一下,國際擴展在服務器中啟用。我正在使用控制面板。它在 Codeigniter 3 上運行良好。郵件功能在我的服務器中使用 row 方法,如下所示:$to = '[email protected]';$subject = 'Test message';$message = 'Hello';$headers = 'From: [email protected]' . "\r\n" .        'Reply-To: [email protected]' . "\r\n" .        'X-Mailer: PHP/' . phpversion();mail($to, $subject, $message, $headers);請幫忙。提前致謝。
查看完整描述

4 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

codeigniter 提供替代類型(Mail、Sendmail 和 SMTP)檢查您的 cpanel 外發電子郵件配置或要求您的提供商檢查 php 的 mail() 配置



查看完整回答
反對 回復 2023-04-28
?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊

在我的例子中,從phpinfo() > intl > ICU 版本4.6 。哪個太舊了。

將其更新到最新版本對我有用。



查看完整回答
反對 回復 2023-04-28
?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

您需要在您的服務器上設置 MTA(郵件傳輸代理)。

例如:Postfix 或 exim,在某些情況下 nullmailer 可以解決問題

可能您可以連接到提供商的 SMTP 中繼


查看完整回答
反對 回復 2023-04-28
?
牛魔王的故事

TA貢獻1830條經驗 獲得超3個贊

我今天遇到了這個,很驚訝地看到圖書館開箱即用。似乎是 CI 的電子郵件庫中的一個問題:


/**

     * Validate email for shell

     *

     * Applies stricter, shell-safe validation to email addresses.

     * Introduced to prevent RCE via sendmail's -f option.

     *

     * @see     https://github.com/codeigniter4/CodeIgniter/issues/4963

     * @see     https://gist.github.com/Zenexer/40d02da5e07f151adeaeeaa11af9ab36

     * @license https://creativecommons.org/publicdomain/zero/1.0/    CC0 1.0, Public Domain

     *

     * Credits for the base concept go to Paul Buonopane <[email protected]>

     *

     * @param string $email

     *

     * @return boolean

     */

    protected function validateEmailForShell(&$email)

    {

        if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@'))

        {

            $email = static::substr($email, 0, ++$atpos)

                . idn_to_ascii(static::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46);

            

        }


        return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email && preg_match('#\A[a-z0-9._+-]+@[a-z0-9.-]{1,253}\z#i', $email));

    }

我沒有時間研究這個方法的全部內容(已經浪費了幾個小時?。?,但能夠繞過它并成功發送電子郵件。創建App/Libraries/Email.php以覆蓋有問題的方法:


<?php namespace App\Libraries;


class Email extends \CodeIgniter\Email\Email{

    protected function validateEmailForShell(&$email){

        return TRUE;

    }

}

然后讓服務返回你的子類App/Config/Services.php:


public static function email(bool $getShared=TRUE){

    return $getShared ? static::getSharedInstance('email') : new \App\Libraries\Email();

}


查看完整回答
反對 回復 2023-04-28
  • 4 回答
  • 0 關注
  • 568 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號