我从另一位开发人员那里继承了一个半完成的项目,并且我对ajax和PHP知之甚少,我发现自己被困在这个联系表单上。
Ajax已成功将字段发送到端点,但根据chromes开发工具,它会抛出500内部服务器错误,也不会发送电子邮件。
如果我在这里遗漏了一些东西,我会非常感谢你的帮助。
这是我在端点中的代码:
<?php
/****************************
* ENQUIRY FORM - Controller *
*****************************
AJAX END-Point, outputs JSON.
Processes user's form inputs, and sends email to site admins.
*/
header('Content-type: application/json');
$form_values = $_POST['enquiry'];
// returned JSON object:
$output = array();
$output['message'] = "form submission received";
$output['enquiry'] = $form_values;
// set values for 'to', 'from' and 'subject'
$send_to = get_option("admin_email");
$subject = "Artbank WebForm Submission";
//change name of "sender"
add_filter( 'wp_mail_from_name', 'artbank_wp_mail_from_name' );
function artbank_wp_mail_from_name( $email_from ) {
return 'Contact Form';
}
$message = "The following submission was received:\n\n"
$message .= "Name: ".$form_values['name'];
$message .= "\nEmail: ".$form_values['email'];
$message .= "\nPhone: ".$form_values['phone'];
$message .= "\nInfo: ".$form_values['info'];
$message .= "\nWishlist Items: ".$form_values['wishlist-items'];
wp_mail($send_to, $subject, $message);
echo json_encode($output);
?>
答案 0 :(得分:0)
你忘记了分号:
$message = "The following submission was received:\n\n";
问候。