繁体   English   中英

wordpress php邮件发送联系表到管理员电子邮件

[英]wordpress php mail send contact form to admin email

我已经建立了一个表单生成器插件。 最后一步是将电子邮件发送给站点管理员,但是,我似乎无法弄清楚如何进行此工作。 这是我的php邮件处理程序:

if (!empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;

} else {
parse_str($_REQUEST['formData'], $formFields);

$html='<html><body>';
foreach ($formFields as $key => $value) {
    $html .= '<p><label>' . $key . ' :</label> ' . $value . '</p>';
}
$html .='</body></html>';
$to = get_option('admin_email');
$subject = "Form Submission";
$txt = $html;
$headers = "From: <sam.skirrow@gmail.com>". "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1"."\r\n";
mail($to,$subject,$txt,$headers);

// if there are no errors process our form, then return a message

// show a message of success and provide a true success variable
$data['success'] = true;
$data['message'] = 'Success!';
}

// return all our data to an AJAX call
echo json_encode($data);

您可以在$ to变量中看到我已添加get_option('admin_email'); 但是,这样做会破坏我的表单(而不是仅输入电子邮件地址。)

您需要加载WordPress才能使用其get_option函数。

将此添加到您的PHP脚本的顶部:

require_once('../../../wp-load.php');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM