Php 通过React中提交的Formik表单通过wp_mail()发送电子邮件
正如上面的标题所述,我想知道如何实现这一点。 是否有方法将提交的Formik值传递到WPMAIL文件,并使用收到的道具将其发送到Php 通过React中提交的Formik表单通过wp_mail()发送电子邮件,php,reactjs,wordpress,formik,Php,Reactjs,Wordpress,Formik,正如上面的标题所述,我想知道如何实现这一点。 是否有方法将提交的Formik值传递到WPMAIL文件,并使用收到的道具将其发送到wp\u mail()函数。以此类推,将道具作为电子邮件发送到指定的电子邮件地址。对于我的情况,我几乎没有找到答案,从我的发现来看,这对我没有任何帮助 有人说,在我的情况下,你必须注册休息路线/联系人,但这对我没有帮助 目前,我必须在ContactScreen.js中执行以下操作: <div className="w-full"> &l
wp\u mail()
函数。以此类推,将道具作为电子邮件发送到指定的电子邮件地址。对于我的情况,我几乎没有找到答案,从我的发现来看,这对我没有任何帮助
有人说,在我的情况下,你必须注册休息路线/联系人,但这对我没有帮助
目前,我必须在ContactScreen.js中执行以下操作:
<div className="w-full">
<div className="mx-4 rounded-lg">
<Formik
initialValues={{ name: '', email: '', phone: '', message: '',}}
validationSchema={SignupSchema}
onSubmit={(values, {resetForm}) => {
this.setState({values: values})
alert(JSON.stringify(this.state.values, null, 2));
resetForm({ values: '' })
}}
>
{({ errors, touched }) => (
<FormikForm className="bg-lightorange rounded pt-8 pb-16 px-20 mb-4 " method="POST">
<div className="flex flex-wrap -mx-3 mb-2">
<div className="w-full md:w-1/2 px-3">
<div className={`${errors.name && touched.name ? 'display-block invalid-message' : 'display-none'} rounded h-8 mb-2 text-xs ease-in-out duration-300`}><ErrorMessage name="name"/></div>
<FormikField placeholder="Naam" type="text" name="name" className={`appearance-none block w-full active:bg-white-100 rounded my-2 py-3 px-8 leading-10 focus:outline-none focus:bg-white ${errors.name && touched.name ? 'invalid' : null}`} />
</div>
<div className="w-full md:w-1/2 px-3">
<div className={`${errors.email && touched.email ? 'display-block invalid-message' : 'display-none'} rounded h-8 mb-2 text-xs ease-in-out duration-300`}><ErrorMessage name="email"/></div>
<FormikField placeholder="E-mailadres" type="email" name="email" className={`appearance-none block w-full active:bg-white-100 rounded my-2 py-3 px-8 leading-10 focus:outline-none focus:bg-white ${errors.email && touched.email ? 'invalid' : null}`} />
</div>
</div>
<div className="flex flex-wrap -mx-3 px-3 my-2">
<div className="w-full">
<div className={`${errors.phone && touched.phone ? 'display-block invalid-message' : 'display-none'} rounded h-8 mb-2 text-xs ease-in-out duration-300`}><ErrorMessage name="phone"/></div>
<FormikField placeholder="Telefoonnummer" type="text" name="phone" maxLength="12" className={`appearance-none block w-full active:bg-white-100 rounded my-2 py-3 px-8 leading-10 focus:outline-none focus:bg-white ${errors.phone && touched.phone ? 'invalid' : null}`}/>
</div>
</div>
<div className="flex flex-wrap -mx-3 px-3 my-2">
<div className="w-full">
<div className={`${errors.message && touched.message ? 'display-block invalid-message' : 'display-none'} rounded h-8 mb-2 text-xs ease-in-out duration-300`}><ErrorMessage name="message"/></div>
<FormikField placeholder="Bericht" as="textarea" name="message" rows={4} className={`appearance-none block w-full resize-none active:bg-white-100 rounded my-2 py-3 px-8 leading-10 focus:outline-none focus:bg-white ${errors.message && touched.message ? 'invalid' : null}`}/>
</div>
</div>
<div className="flex items-center justify-between">
<Button type="submit">Bericht versturen</Button>
</div>
</FormikForm>
)}
</Formik>
</div>
我怎样才能做到这一点?还是我完全忽略了一些相当简单的事情?
如果需要更详细的信息,请在下面告诉我现在就别提了。我刚刚将axios发布到一个新注册的rest_api路由。从那里获取了带有响应的url
<?php
header("Access-Control-Allow-Origin: *");
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
if (empty($_POST['name']) && empty($_POST['email'])) die();
if ($_POST) {
http_response_code(200);
$to = "example@gmail.com";
$subject = $_POST['name'];
$from = $_POST['email'];
$msg = $_POST['number'] . $_POST['message'];
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=UTF-8\r\n";
$headers.= "From: <" . $from . ">";
wp_mail($to, $subject, $msg, $headers);
echojson_encode(array(
"sent" => true
));
}
else {
echojson_encode(["sent" => false, "message" => "Something went wrong"]);
}