繁体   English   中英

PHP不从联系表格发送电子邮件

[英]php not sending email from contact form

我正在尝试在php中设置一个简单的电子邮件功能。 仔细研究解决同一问题的其他问题,看来我在做答案说的同样的事情。 但是,当我尝试发送电子邮件时,它不会发送。

的HTML

<form id="contactMeForm">
    <div class="formField">
        <label for="senderName">Name:</label>
        <input type="text" id="senderName" class="textField" placeholder="Your name" />
    </div>
    <div class="formField">
        <label for="senderEmail">Email:</label>
        <input type="text" id="senderEmail" class="textField" placeholder="Your email" />
    </div>
    <div class="formField">
        <label for="contactReason">Contact reason:</label>
        <select id="contactReason">
            <option></option>
            <option>I'd like a quote for a website.</option>
        </select>
    </div>
    <div class="formField" id="message">
        <div id="senderPhone">
            <label for="returnPhone">Contact number:</label>
            <input type="text" id="returnPhone" class="textField" placeholder="Best phone number to reach you at." />
        </div>
        <label for="senderMessage">Message:</label>
        <textarea id="senderMessage"></textarea>
    </div>

JS

$.ajax({
    type: "POST",
    url: "scripts/email.php",
    data: {name: senderName, email: senderEmail, reason: contactReason, phone: returnPhone, message: senderMessage},
    dataType: "json",
    success: function(response){
        contactMeForm.style.display = "none";
        formButtons.style.display = "block";
        confirmMessage.style.display = "block";
        buttons[1].style.display = "none";
        contactMeHeader[0].textContent = "Your message has been sent.";
    }
})

的PHP

<?php
    $name = $_POST["name"];
    $email = $_POST["email"];
    $reason = $_POST["reason"];
    $phone = $_POST["phone"];
    $headers = "From: " .$email ."\r\n";
    $message = $_POST["message"];

    mail("robbyt15@gmail.com", $reason, $message, $headers);
    echo json_encode(array($name, $email, $reason, $phone, $message));
?>

php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 25

我正在Windows计算机上使用EasyPHP运行Apache服务器。 我也没有收到任何错误消息。

我猜没有一个字段正在填充。 您需要将name属性添加到每个字段中,这就是PHP在$_POST数组中寻找的内容。

<input type="text" id="senderEmail" class="textField" placeholder="Your email" name="email" />

暂无
暂无

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

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