Php 如何设置网站联系人表单以发送电子邮件

Php 如何设置网站联系人表单以发送电子邮件,php,html,web,Php,Html,Web,我正在我的网站上工作,我有一个小问题 我希望联系人表单以电子邮件形式向我发送用户发布的信息 我做了一些研究,这不能用html或javascript完成,但可以用php完成 我在网上得到了一些php代码片段并放到了网站上,但它不起作用,而且我也不能真正解决它,因为我不懂php。。我需要一些帮助我将链接放在网站的github repo上我不介意任何人看一看并提供解决方案联系人表单在store.html页面上,处理邮件请求的php文件称为mail_handler.php 谢谢 非常感谢 检查您的代码

我正在我的网站上工作,我有一个小问题 我希望联系人表单以电子邮件形式向我发送用户发布的信息 我做了一些研究,这不能用html或javascript完成,但可以用php完成 我在网上得到了一些php代码片段并放到了网站上,但它不起作用,而且我也不能真正解决它,因为我不懂php。。我需要一些帮助我将链接放在网站的github repo上我不介意任何人看一看并提供解决方案联系人表单在store.html页面上,处理邮件请求的php文件称为mail_handler.php 谢谢 非常感谢

检查您的代码,您必须将“lname”更改为“email”

您是否可以包括返回的日志和错误?如果问题仍然存在,请与网站所有者联系,此页面将不起作用。HTTP错误405…这就是错误Hi很抱歉,我在回到这里之前完成了网站的其他部分。。我按照你的指示做了,但我仍然有错误我已经在git hub repo中添加了错误代码的快照..我对web开发还是新手,所以我还没有完全理解这些概念哈哈
$('#contactForm').on('submit', submitForm); // step 1: connect submit action to button
function submitForm() {
    // step 2: get data from input fields
    var name = $("#name").val();
    var email = $("#email").val();
    var message = $("#message").val();


    // check if data is present
    console.log(name, email, message);

    // step 3: send data to contact form mailer
    $.ajax({
        method: 'post',
        url: 'http://example.com/api/contact.php', //your API, If you do not have one, no data will sent
        dataType: 'json',
        data: {
            'to_email': 'your.email@example.com',
            'from_fname': fname,
            'from_email': email,
            'message': message
        },
        'success': formSuccess,
        'error': formError
    });
    return false;//inorder not to referesh the page.
}
// step 4: handle response (success or error)
function formSuccess(result) {
    if (result.error) { // there was an error
        alert(result.error);
    } else { // everything went well
        alert(result.response);
        $("#contactForm")[0].reset(); //instead of saying getElementById
        // clear input fields
    }
}
// step 5: handle error
function formError(xhr, status, error) {
    alert("There has been an error. Please retry");
}