簡體   English   中英

React - 使用 wp_mail 發送電子郵件

[英]React - sending an email using wp_mail

我正在嘗試在 React 中創建一個聯系表單,我想用它來通過我的 Wordpress 安裝發送電子郵件。 通常,如果我進行 AJAX 調用,我必須將提交函數的名稱作為如下操作傳遞:

jQuery.ajax({
    type: 'POST',
    url: 'admin-ajax.php',
    data: { action: 'send_form' }
}).done(function(response) {
    alert(response);
});

但是,由於我沒有在 React 應用程序中使用 jQuery,因此我使用fetch進行調用:

const res = await fetch('admin-ajax.php', {
    method: 'POST',
    body: JSON.stringify(this.state.values),
    headers: {
        "Content-Type": "application/json"
    }
});

我的問題是,如何在 React 調用中傳遞操作send_form

您可以附加到您的body參數:

body: JSON.stringify({...this.state.values, 'action': 'send_form'})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM