联系人表格未发送消息

时间:2019-03-24 04:05:09

标签: php html

我在php中的联系表没有将消息发送到邮件,所以我需要知道这里的问题是什么 您将在此处找到带有文件名的HTML表单:index.php 和php形式,名称为:mail.php

<form class="form" action="mail.php" method="post" name="contactform">
    <input class="name" type="text" placeholder="Name" name="name">
    <input class="email" type="email" placeholder="Email" name="email" >
    <input class="phone" type="text" placeholder="Phone No:" name="phone">
    <textarea class="message" id="message" cols="30" rows="10" placeholder="Message"name="message"  ></textarea>
    <input class="submit-btn" type="submit" value="Submit">
</form>

<?php
if (isset($_POST['submit']) ) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $from = 'From:  phone'; 
    $to = 'modysaid26@gmail.com'; 
    $subject = 'message';

    $body = "From: $name\n E-Mail: $email\n Phone Number: $phone\n Message:\n $message";

    if (isset($_POST['submit'])) {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been submitted</p>';
        } else { 
            echo '<p>Something went wrong, please try again!</p>'; 
        }
    }
}
?>

3 个答案:

答案 0 :(得分:0)

<input class="submit-btn" name='submit' type="submit" value="Submit">

您缺少添加名称来提交按钮,因此您的案件if (isset($_POST['submit']) ) {失败了

答案 1 :(得分:0)

您不需要在表单标签上放置名称,也可以删除该类:  <form action="mail.php" method="post">

答案 2 :(得分:0)

缺少您的“首先提交”按钮名称,请使用

<input class="submit-btn" type="submit" value="Submit" name="submit">

您的第二个电子邮件命令(mail ($to, $subject, $body, $from))没有正确的电子邮件标题。进入您的$from 请使用以下参数定义标题

$email_headers = "From: ".$from_name." <".$from_email.">\r\n".
"Reply-To: ".$reply_to."\r\n" ;
if ($cc) $email_headers.="Cc: ".$cc."\r\n";
if ($bcc) $email_headers.="Bcc: ".$bcc."\r\n";
$email_headers.="MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";

$email_body=$_POST['message'];

然后使用

发送
mail($to, $subject, $email_body, $email_headers);

然后您的电子邮件应正确发送。