Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 精品一区二区免费视频,www.色.com,国产成+人+综合+欧美亚洲

          整合營(yíng)銷(xiāo)服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢(xún)熱線:

          PHP-使用PHP發(fā)送電子郵件

          PHP-使用PHP發(fā)送電子郵件

          須在php.ini文件中正確配置PHP ,并詳細(xì)說(shuō)明系統(tǒng)如何發(fā)送電子郵件。打開(kāi)/ etc /目錄中的php.ini文件,并找到標(biāo)題為[郵件功能]的部分。

          Windows用戶(hù)應(yīng)確保提供了兩個(gè)指令。第一個(gè)稱(chēng)為SMTP,它定義您的電子郵件服務(wù)器地址。第二個(gè)稱(chēng)為sendmail_from,它定義您自己的電子郵件地址。

          Windows的配置應(yīng)如下所示:

          [mail function]
          ; For Win32 only.
          SMTP=smtp.secureserver.net
          
          ; For win32 only
          sendmail_from=webmaster@tutorialspoint.com
          

          Linux用戶(hù)只需要讓PHP知道他們sendmail應(yīng)用程序的位置即可。路徑和任何所需的開(kāi)關(guān)應(yīng)指定給sendmail_path指令。

          Linux的配置應(yīng)該看起來(lái)像這樣-

          [mail function]
          ; For Win32 only.
          SMTP=; For win32 only
          sendmail_from=; For Unix only
          sendmail_path=/usr/sbin/sendmail -t -i
          

          現(xiàn)在您可以開(kāi)始了-

          發(fā)送純文本電子郵件

          PHP利用mail()函數(shù)發(fā)送電子郵件。此功能需要三個(gè)必填參數(shù),用于指定收件人的電子郵件地址,郵件主題和實(shí)際郵件,此外還有其他兩個(gè)可選參數(shù)。

          mail( to, subject, message, headers, parameters );

          這是每個(gè)參數(shù)的說(shuō)明。


          一旦調(diào)用了郵件功能,PHP將嘗試發(fā)送電子郵件,如果成功,它將返回true;如果失敗,則將返回false。

          可以將多個(gè)收件人指定為逗號(hào)分隔列表中mail()函數(shù)的第一個(gè)參數(shù)。

          發(fā)送HTML電子郵件

          當(dāng)您使用PHP發(fā)送文本消息時(shí),所有內(nèi)容將被視為簡(jiǎn)單文本。即使您將HTML標(biāo)簽包含在文本消息中,它也將顯示為簡(jiǎn)單文本,并且不會(huì)根據(jù)HTML語(yǔ)法設(shè)置HTML標(biāo)簽的格式。但是PHP提供了將HTML消息作為實(shí)際HTML消息發(fā)送的選項(xiàng)。

          發(fā)送電子郵件時(shí),您可以指定Mime版本,內(nèi)容類(lèi)型和字符集來(lái)發(fā)送HTML電子郵件。

          以下示例將HTML電子郵件發(fā)送到xyz@somedomain.com,并將其復(fù)制到afgh@somedomain.com。您可以使用以下方式對(duì)程序進(jìn)行編碼:它應(yīng)接收用戶(hù)的所有內(nèi)容,然后發(fā)送電子郵件。

          <html>
             
             <head>
                <title>Sending HTML email using PHP</title>
             </head>
             
             <body>
                
                <?php
                   $to="xyz@somedomain.com";
                   $subject="This is subject";
                   
                   $message="<b>This is HTML message.</b>";
                   $message .="<h1>This is headline.</h1>";
                   
                   $header="From:abc@somedomain.com \r\n";
                   $header .="Cc:afgh@somedomain.com \r\n";
                   $header .="MIME-Version: 1.0\r\n";
                   $header .="Content-type: text/html\r\n";
                   
                   $retval=mail ($to,$subject,$message,$header);
                   
                   if( $retval==true ) {
                      echo "Message sent successfully...";
                   }else {
                      echo "Message could not be sent...";
                   }
                ?>
                
             </body>
          </html>

          通過(guò)電子郵件發(fā)送附件

          要發(fā)送包含混合內(nèi)容的電子郵件,需要將Content-type標(biāo)頭設(shè)置為multipart / mixed。然后可以在邊界內(nèi)指定文本和附件節(jié)。

          邊界以?xún)蓚€(gè)連字符開(kāi)頭,后跟一個(gè)唯一的數(shù)字,該數(shù)字不能出現(xiàn)在電子郵件的消息部分。PHP函數(shù)md5()用于創(chuàng)建32位十六進(jìn)制數(shù)字以創(chuàng)建唯一數(shù)字。表示電子郵件最后部分的最后邊界也必須以?xún)蓚€(gè)連字符結(jié)尾。

          者 | Mateusz Iwaniuk

          譯者 | 明明如月,責(zé)編 | 夕顏

          出品 | CSDN(ID:CSDNnews)

          文章配套代碼: https://github.com/iwaniukooo11/email-sender

          現(xiàn)在,即使是創(chuàng)建最基本的網(wǎng)站,程序員也必須使用現(xiàn)代的功能和技術(shù)。甚至像為你的朋友創(chuàng)建簡(jiǎn)單的投資組合這樣的基本項(xiàng)目也可能涉及到一些問(wèn)題,比如從聯(lián)系人表單接收數(shù)據(jù)。有很多方法可以讀取這些數(shù)據(jù)。你可以將表單與數(shù)據(jù)庫(kù)連接起來(lái),然后從數(shù)據(jù)庫(kù)中讀取傳入的消息來(lái)實(shí)現(xiàn)功能,但這樣做會(huì)給不懂技術(shù)的客戶(hù)造成困難。

          你為什么不通過(guò)發(fā)送電子郵件傳輸信息?

          不使用數(shù)據(jù)庫(kù)就能接收到傳入的消息,絕對(duì)是最佳選擇,也是最方便用戶(hù)的選擇。但問(wèn)題來(lái)了—如何實(shí)現(xiàn)呢?你可能認(rèn)為需要使用某種后端語(yǔ)言。

          實(shí)際上,你不必使用任何如 php 或 python 這種后端語(yǔ)言,你甚至不需要用到 node.js!你需要的就是一個(gè)簡(jiǎn)單的EmailJS 庫(kù)。

          本文將介紹下面兩個(gè)重要功能:

          • 配置 emailjs 帳戶(hù)

          • 使用 JS 發(fā)送電子郵件

          請(qǐng)注意,在我的項(xiàng)目中,我使用了 gulp 和 webpack,我在 src 文件夾存放源碼,dist 存放最終發(fā)布版本的代碼。

          我將分 5 個(gè)步驟向你展示如何從頭開(kāi)始構(gòu)建電子郵件發(fā)送器。

          步驟1-用 HTML 創(chuàng)建表單

          首先需要?jiǎng)?chuàng)建一個(gè) HTML 表單。你不必放置像 required 或 max 這種驗(yàn)證屬性,因?yàn)樯院螅琾reventDefault 函數(shù)將在你的提交事件上運(yùn)行,它會(huì)讓這些屬性的處理失效。

          表單中最重要的是為每個(gè)輸入放置 name 屬性,后面會(huì)用到。

          我的非常簡(jiǎn)單的表單是這樣的:

          src/html/index.html

           <form class="form"> <input name='name' type="text" placeholder="Your name..." class="form__input" /> <input name='topic' type="text" placeholder="Topic..." class="form__input" /> <textarea name='message' type="text" placeholder="Your Message..." class="form__input" ></textarea>

          <input type="submit" value="send" class="form__input form__input--button"> </form>

          步驟2-注冊(cè)成為 email 用戶(hù)

          要配置你的電子郵件,你必須注冊(cè)電子郵件服務(wù)。別擔(dān)心—使用這個(gè)網(wǎng)站非常方便和省時(shí)。

          登入后,系統(tǒng)會(huì)詢(xún)問(wèn)你的電子郵件服務(wù),它位于個(gè)人電子郵件服務(wù)區(qū)(personal email service)。在我的例子中,我選擇了 gmail。

          然后,你需要連接你的 gmail 帳戶(hù)。這將用來(lái)發(fā)送電子郵件給你客戶(hù)。例如,如果你關(guān)聯(lián)了 xyz@gmail.com 賬戶(hù),你后續(xù)發(fā)送的郵件都將從這個(gè)郵箱發(fā)出。所以不要擔(dān)心“ Send email on your behalf” 這個(gè)授權(quán)信息—這正是你需要的!

          連接完 gmail 賬戶(hù)后,點(diǎn)擊添加服務(wù)(add service)按鈕。

          步驟3-創(chuàng)建郵件模板

          如果你已經(jīng)成功連接了你的 gmail 賬戶(hù),你現(xiàn)在應(yīng)該在信息中心中。現(xiàn)在需要?jiǎng)?chuàng)建電子郵件模板了。

          切換到電子郵件模板卡,并單擊創(chuàng)建一個(gè)新的模板(create a new template)。界面非常友好,所以創(chuàng)建模板不會(huì)有任何問(wèn)題。

          你可以選擇模板的名稱(chēng)和 ID。我稱(chēng)之為“我的神奇模板(my_amazing_template)”。

          接下來(lái),你必須指定郵件的內(nèi)容。

          模板的變量值來(lái)自 input 中的 `name` 屬性。你已將變量插入`{{{}}}`符號(hào)中。

          不要忘記在“收件人”部分 (右側(cè)) 添加電子郵件地址。你的電子郵件將被發(fā)送到該電子郵件地址上。截圖中的收件人郵箱是我自己的公司郵箱。

          這是我的簡(jiǎn)單模板,它使用來(lái)自 HTML 表單里的 3 個(gè)變量。我還指定了接收電子郵件的主題。

          步驟4-保存 API 密鑰

          這部分沒(méi)什么特別的。Emailjs 共享授權(quán) API 密鑰,將在發(fā)送電子郵件時(shí)使用。當(dāng)然,放這些鑰匙最好的地方是`.env` 配置。但是因?yàn)槲沂褂玫氖呛?jiǎn)單的靜態(tài)文件,我不想使用服務(wù)器配置,所以我將它們保存在 apikeys 文件中,然后再將它們導(dǎo)入。

          你的 USER_ID 位于 Account > API Keys 菜單下。

          TEMPLATE_ID 位于模板的標(biāo)題下面。

          這是我基于不存在的 keyssrc / js / apikeys. js 的示例配置.

          src/js/apikeys.js

          export default { USER_ID :'user_DPUd-rest-of-my-id', TEMPLATE_ID:'my_amazing_template'}

          如果需要將源碼發(fā)布到 GITHUB,不要忘記將 APIKEYS 文件添加到 .GITIGNORE文件中

          步驟5-發(fā)送電子郵件

          現(xiàn)在是該項(xiàng)目最后也是最重要的部分的了。現(xiàn)在我們必須使用 javascript 發(fā)送電子郵件。

          首先,你必須下載 emailjs 包。

          npm i emails-com

          然后,轉(zhuǎn)到 js 文件,導(dǎo)入庫(kù)和 apikeys。

          src/js/main.js

          import emailjs from 'emailjs-com'import apiKeys from './apikeys'

          現(xiàn)在是編寫(xiě)發(fā)送電子郵件功能的時(shí)候了

          src/js/main.js

          const sendEmail=e=> { e.preventDefault

          emailjs .sendForm('gmail', apiKeys.TEMPLATE_ID, e.target, apiKeys.USER_ID) .then( result=> { console.log(result.text) }, error=> { console.log(error.text) } )}

          sendForm 函數(shù)有4個(gè)參數(shù):

          你的電子郵件的 ID,在這里:

          TEMPLATE_ID 來(lái)自 apikey 文件,

          事件對(duì)象來(lái)自你的表單提交

          USER_ID 來(lái)自 apikey 文件,

          最后,查找表單并添加提交事件監(jiān)聽(tīng)器:

          src/js/main.js

          const form=document.querySelector('.form')form.addEventListener('submit',sendEmail)

          正如我前面提到的,由于 `preventDefault` 函數(shù),屬性驗(yàn)證將無(wú)法工作。你必須使用 JS 自己進(jìn)行驗(yàn)證和清除輸入。

          以上就是全部?jī)?nèi)容,接下來(lái)讓我們測(cè)試一下。

          填寫(xiě)頁(yè)面上的表單并發(fā)送。

          我收到電子郵件,內(nèi)容正是根據(jù)我們的模板和表單數(shù)據(jù)渲染出來(lái)的。

          通過(guò)上圖可以看出,所有的變量的值都填充到了正確的位置上。

          總結(jié)

          通過(guò)本文的介紹你會(huì)發(fā)現(xiàn)用 JS 發(fā)送郵件并非難事。

          使用 emailjs,你可以簡(jiǎn)單的方式發(fā)送電子郵件。

          我相信你未來(lái)的用戶(hù)會(huì)很高興收到來(lái)自他們網(wǎng)頁(yè)上表單填寫(xiě)數(shù)據(jù)的t郵件,相信本文對(duì)你有幫助。

          這篇文章的配套代碼在這里: https://github.com/iwaniukooo11/email-sender

          原文鏈接:

          https://dev.to/iwaniukooo11/send-e-mails-directly-from-front-end-with-js-5d7d

          本文為CSDN翻譯文章,轉(zhuǎn)載請(qǐng)注明出處。

          ?我們想研發(fā)一個(gè)機(jī)器學(xué)習(xí)框架,6 個(gè)月后失敗了

          ?生產(chǎn)型機(jī)器學(xué)習(xí)已經(jīng)沒(méi)那么困難了?

          ?視頻 | 你不知道的"開(kāi)源"60年秘史

          ?GitHub標(biāo)星10,000+,Apache項(xiàng)目ShardingSphere的開(kāi)源之路

          ?阿里技術(shù)專(zhuān)家告訴你,如何畫(huà)出優(yōu)秀的架構(gòu)圖?

          ?加拿大API平臺(tái)如何做到30%為中國(guó)明星項(xiàng)目?創(chuàng)業(yè)老兵這樣說(shuō)……

          wish I could remember the very first email message I ever sent. Unfortunately, the truth is that I’ve come to take email for granted; for instance, I easily send more email messages than I make phone calls. Because the novelty has long since worn off, the memory of that first email is as lost to me as my first phone call; but I doubt my sense of wonder was any less complete at the time. To someone who has never seen email in action before, that first message can be magical.

          我希望我能記得我發(fā)送的第一封電子郵件。不幸的是,事實(shí)是我已經(jīng)把電子郵件視為理所當(dāng)然;例如,我很容易發(fā)送比打電話更多的電子郵件。因?yàn)樾缕娓性缫严В覍?duì)第一封電子郵件的記憶就像第一次打電話一樣消失了;但我懷疑當(dāng)時(shí)我的驚奇感是否不夠完整。對(duì)于一個(gè)以前從未見(jiàn)過(guò)電子郵件的人來(lái)說(shuō),第一條消息可能很神奇。

          In this article, I’ll try to recapture some of that magic for those of you who have never created a Web site that sends email messages. We’ll see how the PHP server-side scripting language may be set up to send email, and explore how to send complex message types such as HTML email or emails with file attachments.

          在這篇文章中,我將嘗試為那些從未創(chuàng)建過(guò)發(fā)送電子郵件的網(wǎng)站的人重溫其中的一些魔力。我們將了解如何設(shè)置PHP服務(wù)器端腳本語(yǔ)言來(lái)發(fā)送電子郵件,并探索如何發(fā)送復(fù)雜的消息類(lèi)型,如HTML電子郵件或帶有文件附件的電子郵件。

          PHP Email Setup

          PHP電子郵件步驟

          Before we can send email with PHP, we need to set it up to do so, just as you need to set up your email program before it can send messages. Configuration for sending email in PHP is done with the php.ini file, so open up your Web server’s php.ini in whichever editor you normally use.

          在我們用PHP發(fā)送電子郵件之前,我們需要對(duì)它進(jìn)行設(shè)置,就像您需要在它發(fā)送消息之前設(shè)置電子郵件程序一樣。用PHP發(fā)送電子郵件的配置是通過(guò)PHP.ini文件完成的,所以在您通常使用的編輯器中打開(kāi)Web服務(wù)器的PHP.ini。

          If you don’t run your own server, but instead have a PHP-equipped Web host, you can safely assume that everything in this section has been done for you, and skip ahead.

          如果您沒(méi)有運(yùn)行自己的服務(wù)器,而是有一個(gè)配備了PHP的Web主機(jī),那么您可以放心地假設(shè)本節(jié)中的所有內(nèi)容都已為您完成,然后跳過(guò)。

          In the section entitled [mail function] in the php.ini file, you’ll find three settings: SMTP, sendmail_from, and sendmail_path. If your server runs on a Windows machine, you’ll want to set the SMTP option to point to your SMTP server (or your ISP’s SMTP server, if you’re setting up PHP on your home machine). If instead you’re setting up PHP on a Linux (or other Unix-based OS) server, you’ll want to set the sendmail_path option to point to the sendmail program on your server, passing it the -t option. You can use the SMTP option in Linux instead if you don’t have sendmail set up.

          在php.ini文件中標(biāo)題為[mail function]的部分中,您將找到三個(gè)設(shè)置:SMTP、sendmail_from和sendmail_path。如果您的服務(wù)器在Windows計(jì)算機(jī)上運(yùn)行,則需要將SMTP選項(xiàng)設(shè)置為指向您的SMTP服務(wù)器(或ISP的SMTP服務(wù)器,如果您在家庭計(jì)算機(jī)上設(shè)置PHP)。如果要在Linux(或其他基于Unix的操作系統(tǒng))服務(wù)器上設(shè)置PHP,則需要將sendmail_path選項(xiàng)設(shè)置為指向服務(wù)器上的sendmail程序,并將-t選項(xiàng)傳遞給它。如果沒(méi)有設(shè)置sendmail,則可以在Linux中使用SMTP選項(xiàng)。

          In either case, you’ll want to set the sendmail_from option to your email address, or whichever address you’d like to appear as the default ‘from’ address for emails sent from PHP scripts.

          在任何一種情況下,您都需要將sendmail_from選項(xiàng)設(shè)置為您的電子郵件地址,或者您希望顯示為從PHP腳本發(fā)送的電子郵件的默認(rèn)“from”地址的任何地址。

          Here’s how the section might look on a typical Windows server, or on a Linux server without sendmail:

          以下是該部分在典型Windows服務(wù)器上的外觀,或在沒(méi)有sendmail的Linux服務(wù)器上的展示:

          [mail function]
          ; Setup for Windows systems
          SMTP=smtp.my.isp.net
          sendmail_from=me@myserver.com
          And here’s how it might look on a Linux server with sendmail:
          
          [mail function]
          ; Setup for Linux systems
          sendmail_path=/usr/sbin/sendmail -t
          sendmail_from=me@myserver.com
          With those settings in place, restart your Web server and you’re ready to go!

          Sending Plain Email

          發(fā)送普通電子郵件

          It doesn’t come much easier than the procedure to send plain text email in PHP. In fact, you can do it in just one line in a PHP script:

          用PHP發(fā)送純文本電子郵件的過(guò)程并不容易。事實(shí)上,您可以在PHP腳本的一行中完成:

          <?php
          mail('recipient@some.net', 'Subject', 'Your message here.');
          ?>

          The above line would send an email message to recipient@some.net with ‘Subject‘ as the subject line and ‘Your message here.‘ as the message body. As you can see, PHP’s mail function makes sending email exceedingly simple, but there are a few advanced tricks we can use to get more out of this simple function.

          上述行將向發(fā)送電子郵件recipient@some.net以“Subject”作為標(biāo)題,以“Your message here.”作為郵件正文。正如您所看到的,PHP的郵件函數(shù)使發(fā)送電子郵件變得非常簡(jiǎn)單,但是我們可以使用一些高級(jí)技巧來(lái)從這個(gè)簡(jiǎn)單的函數(shù)中獲得更多信息。

          First of all, if the mail system you configured in your php.ini file rejects a message you try to send (for example, if the ‘to’ address is not a valid email address), this function will display an error message in the user’s browser. Like most PHP functions, however, error messages may be suppressed by preceding the function name with an @ symbol. Combine this with the fact that the mail function returns either true or false depending on whether the email was accepted by the mail sending system, and you have a formula to send email with appropriate error checking:

          首先,如果您在php.ini文件中配置的郵件系統(tǒng)拒絕您嘗試發(fā)送的郵件(例如,如果“to”地址不是有效的電子郵件地址),此函數(shù)將在用戶(hù)瀏覽器中顯示錯(cuò)誤消息。但是,與大多數(shù)PHP函數(shù)一樣,可以通過(guò)在函數(shù)名前面加上@符號(hào)來(lái)抑制錯(cuò)誤消息。再加上郵件函數(shù)根據(jù)郵件發(fā)送系統(tǒng)是否接受郵件而返回true或false,并且您有一個(gè)發(fā)送電子郵件并進(jìn)行適當(dāng)錯(cuò)誤檢查的公式:

          <?php
          if (@mail($to, $subject, $message)) {
          echo('<p>Mail sent successfully.</p>');
          } else {
          echo('<p>Mail could not be sent.</p>');
          }
          ?>

          Note that just because an email message could be sent doesn’t guarantee it will arrive at its destination. An email address can be valid (i.e. correctly formed) but not actually exist. For instance, you can successfully send a message to nonexistant.user@hotmail.com — that is, the mail function will return true — but the message will bounce because no such user exists. PHP provides no built-in means of detecting when this happens.

          請(qǐng)注意,僅僅因?yàn)榭梢园l(fā)送電子郵件并不保證它會(huì)到達(dá)目的地。電子郵件地址可能有效(即格式正確),但實(shí)際上不存在。例如,您可以成功地向不存在的用戶(hù)發(fā)送消息。user@hotmail.com-也就是說(shuō),郵件函數(shù)將返回true-但郵件將反彈,因?yàn)椴淮嬖谶@樣的用戶(hù)。PHP沒(méi)有提供檢測(cè)何時(shí)發(fā)生這種情況的內(nèi)置方法。

          When you want to send a message to multiple recipients, you can just list their email addresses one after another, separated by commas, in the first parameter. For example:

          當(dāng)您想向多個(gè)收件人發(fā)送郵件時(shí),您可以在第一個(gè)參數(shù)中逐個(gè)列出他們的電子郵件地址,并用逗號(hào)分隔。例如:


          主站蜘蛛池模板: 国产探花在线精品一区二区| 国产对白精品刺激一区二区| 无码国产伦一区二区三区视频| 日本香蕉一区二区三区| 日韩久久精品一区二区三区| 成人h动漫精品一区二区无码| 内射少妇一区27P| 中文国产成人精品久久一区| 射精专区一区二区朝鲜| 国产99久久精品一区二区| 日韩免费视频一区| 国产人妖视频一区二区| 亚洲一区二区三区国产精品无码| 国产香蕉一区二区三区在线视频 | 国产一区二区三区在线2021| 亚洲一区二区三区夜色| 精品国产日韩亚洲一区在线| 国产精久久一区二区三区| 久久一区二区三区免费播放| 国产成人一区二区动漫精品 | 亚洲av乱码一区二区三区按摩| 国产精品视频无圣光一区| 色妞AV永久一区二区国产AV| 海角国精产品一区一区三区糖心| 无码人妻一区二区三区精品视频| 亚洲国产精品一区| 一区二区三区在线免费观看视频| 亚欧成人中文字幕一区| 日本一区二区三区在线视频| 精品欧洲av无码一区二区14| 国产伦一区二区三区高清 | 色欲AV无码一区二区三区| 看电影来5566一区.二区| 正在播放国产一区| 一区二区三区福利视频免费观看| 精品国产亚洲一区二区三区| 一区二区三区在线|欧| 日本一区二区不卡视频| 无码人妻久久一区二区三区 | 国模精品一区二区三区| 日韩精品一区二区三区中文|