<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 發送電子郵件 幾乎每個Web應用程序都需要發送電子郵件,無論是簡報還是訂單確認。 這就是為什么Nette Framework提供必要的工具。 本教程將向您介紹如何: **創建電子郵件 發送電子郵件 電子郵件添加附件 在電子郵件中使用模板 電子郵件創建鏈接** 使用Nette \ Mail \ Message類創建電子郵件的示例: ~~~ use Nette\Mail\Message; $mail = new Message; $mail->setFrom('John <john@example.com>') ->addTo('peter@example.com') ->addTo('jack@example.com') ->setSubject('Order Confirmation') ->setBody("Hello, Your order has been accepted."); ~~~ 發送: ~~~ use Nette\Mail\SendmailMailer; $mailer = new SendmailMailer; $mailer->send($mail); ~~~ 除了使用addTo()指定收件人之外,還可以使用addCc()和副本的收件人addBcc()指定副本的收件人。 在所有這些方法中,包括setFrom(),我們可以通過三種方式指定地址: ~~~ $mail->setFrom('john.doe@example.com'); $mail->setFrom('john.doe@example.com', 'John Doe'); $mail->setFrom('John Doe <john.doe@example.com>'); ~~~ HTML內容可以使用setHtmlBody()方法定義: ~~~ $mail->setHtmlBody('<b>Sample HTML</b> <img src="background.gif">'); ~~~ 嵌入的圖像可以使用$ mail-> addEmbeddedFile('background.gif')插入,但是沒有必要。 為什么? 因為Nette Framework會自動找到并插入HTML代碼中引用的所有文件。 此行為可以通過添加FALSE作為setHtmlBody()方法的第二個參數來抑制。 如果HTML電子郵件沒有純文本替代項,則會自動生成。 如果沒有設置主題,它將從<title>元素中獲取。 ## 附件 向電子郵件添加附件很簡單。 為了附加一個文件,我們使用addAttachment方法: ~~~ // attaches example.zip to the e-mail $mail->addAttachment('path/to/example.zip'); // attaches new example.txt file with "Hello John!" in it $mail->addAttachment('example.txt', 'Hello John!'); // attaches example.zip renamed to info.zip $mail->addAttachment('info.zip', file_get_contents('path/to/example.zip')); ~~~ ## 模板 結合了Latte模板系統: ~~~ $latte = new Latte\Engine; $params = [ 'orderId' => 123, ]; $mail = new Message; $mail->setFrom('John <john@example.com>') ->addTo('jack@example.com') ->setHtmlBody($latte->renderToString('email.latte', $params)); ~~~ 文件email.latte: ~~~ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Order Confirmation</title> <style> body { background: url("background.png") } </style> </head> <body> <p>Hello,</p> <p>Your order number {$orderId} has been accepted.</p> </body> </html> ~~~ ## 創建鏈接 Latte Engine本身不提供{link}宏。 如果我們想使用它,我們可以通過調用$ template = $ this-> createTemplate() - > setFile('email.latte')并將它添加到setHtmlBody中來使用一個Presenter或一個組件來為我們創建模板 )。 這樣,我們可以在模板中創建鏈接。 ~~~ use Nette; class MyPresenter { public function actionFoo() { $template = $this->createTemplate()->setFile('email.latte'); $mail = new Message(); $mail->setHtmlBody($template); } } ~~~ 另一個選擇是自己注冊宏。 因為生成鏈接需要一個控制器,我們將它作為參數傳遞給模板: ~~~ use Nette; use Nette\Bridges\ApplicationLatte\UIMacros; function createMessage(Nette\Application\Application $application) /** @var Nette\Application\IPresenter */ $presenter = $application->getPresenter(); $latte = new Latte\Engine; $params = [ 'orderId' => 123, '_presenter' => $presenter, // because of {plink} '_control' => $presenter // because of {link} ]; UIMacros::install($latte->getCompiler()); // This registers macros link, plink and others // ... } ~~~ 在模板中,創建鏈接像在普通模板中。 我們使用絕對地址,所以鏈接總是指向正確的域: ~~~ <a href="{link //Presenter:action}">Odkaz</a> ~~~ ## 自定義郵件 默認郵件程序使用PHP功能郵件。 如果您需要通過SMTP服務器發送郵件,您可以使用SmtpMailer。 ~~~ $mailer = new Nette\Mail\SmtpMailer([ 'host' => 'smtp.gmail.com', 'username' => 'john@gmail.com', 'password' => '*****', 'secure' => 'ssl', ]); $mailer->send($mail); ~~~ 您還可以創建自己的郵件程序 - 它是一個實現Nette \ Mail \ IMailer界面的類。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看