任何人都可以帮我这个联系表格发送电子邮件php代码

时间:2017-02-06 09:24:06

标签: php html forms email

我是php的新手,但是从网上下载代码并进行了编辑。表格是我网站上的联系表格,应该给我发电子邮件。但在编辑之后,几次尝试后都无法给我发电子邮件。

HTML表格

<h3>Use This Contact Form To Reach Us</h3>
<form action="thankyou.php" method="post">
    <input type="text" name="name" id="name" maxlength="30" placeholder="Full Name">
    <input type="email" name="email" id="email" maxlength="50" placeholder="Email">
    <input type="text" name="phone" id="phone" maxlength="10" placeholder="Phone">
    <textarea placeholder="Message" name="message" id="message"></textarea>
    <input type="submit" id="submit" value="Submit">
</form>

这是php页面。

thankyou.php

<?php
if ($_POST["submit"]) {
    $recipient   = "marketing@smartpay.com";
    $subject     = "MESSAGE FROM ONLINESMARTPAY.COM";
    $sendername  = $_POST["name"];
    $senderemail = $_POST["email"];
    $senderphone = $_POST["phone"];
    $message     = $_POST["message"];
    $mailBody    = "FullName: $sendername\nEmailAddress: $senderemail\nPhoneNumber: 

$senderphone\n\n$message";
    mail($recipient, $subject, $mailBody, "From: $sender <$senderemail>");
}
?>

1 个答案:

答案 0 :(得分:0)

我怀疑您的表单中不存在PropertyChanged.Fody的原因之一是您没有$_POST['submit']的任何输入类型您应该在您的name=submit上添加name=submit属性提交按钮目前您的提交按钮如下:

<input type="submit" id="submit" value="Submit">代替<input type="submit" id="submit" value="Submit" name="submit">

然后在您的电子邮件中,您需要设置标题。

<h3>Use This Contact Form To Reach Us</h3>
<form action="thankyou.php" method="post">
    <input type="text" name="name" id="name" maxlength="30" placeholder="Full Name">
    <input type="email" name="email" id="email" maxlength="50" placeholder="Email">
    <input type="text" name="phone" id="phone" maxlength="10" placeholder="Phone">
    <textarea placeholder="Message" name="message" id="message"></textarea>
    <input type="submit" id="submit" value="Submit" name="submit">
</form>

<强> thankyou.php

<?php
if ($_POST["submit"]) {
    $recipient   = "marketing@smartpay.com";
    $subject     = "MESSAGE FROM ONLINESMARTPAY.COM";
    $sendername  = $_POST["name"];
    $senderemail = $_POST["email"];
    $senderphone = $_POST["phone"];
    $message     = $_POST["message"];
    $headers     = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From:' . $sendername . '<' . $senderemail . '>' . "\r\n";
    $mailBody = "FullName: $sendername\nEmailAddress: $senderemail\nPhoneNumber:$senderphone\n\n$message";
    if (mail($recipient, $subject, $mailBody, $headers)) {
        echo "email sent";
    } else {
        echo "could not send email"; // something wrrong with your server config
    }
}
?>