【问题标题】:Failed to Send Contact Information to the mail id无法将联系信息发送到邮件 ID
【发布时间】:2018-04-22 02:28:15
【问题描述】:

我开发了此代码,用于在填写联系表格后发送联系信息。但是,它仍然无法正常工作。它不断显示消息“Not Ok”。我无法找出错误。请指导我使此代码可行。

抱歉,我没有添加任何 php 代码- 请在下面检查它现在更新了一个。

<?php

    if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email']) && isset($_POST['message'])){
        if(!empty($_POST['fname'])&& !empty($_POST['lname']) && !empty($_POST['email']) && !empty($_POST['message'])){
            $fname = $_POST['fname'];
            $lname = $_POST['lname'];
            $email = $_POST['email'];
            $message = $_POST['message'];

            if(!filter_var($email, FILTER_VALIDATE_EMAIL)){

                echo 'Kindly proivde valid email id';
            }else{
                    $body = $fname."\n".$lname."\n".$email."\n".$message;
                    if(mail('example@mail.com','Website Response',$body,'From: response@self.com')){
                        echo 'Thanks for contacting us.';
                    } else {
                        echo "Error Occured in sending mail";
                    }
            }

        } else{
            echo 'All fields are mandatory';
        }
    } else{
            echo 'Not ok';
    }


    ?>


    <!DOCTYPE html>
    <html>
    <head>
    <style>
    input[type=text], input[type=email], textarea {
        width: 100%;
        padding: 12px;
        border: 1px solid #ccc;
        border-radius: 4px;
        box-sizing: border-box;
        margin-top: 6px;
        margin-bottom: 16px;
        resize: vertical;
    }

    input[type=submit] {
        background-color: #4CAF50;
        color: white;
        padding: 12px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }

    input[type=submit]:hover {
        background-color: #45a049;
    }

    .container {
        border-radius: 5px;
        background-color: #f2f2f2;
        padding: 20px;
    }
    </style>
    </head>
    <body>

    <h3>Contact Form</h3>

    <div class="container">
      <form action="" method="POST">
        <label for="fname">First Name</label>
        <input type="text" id="fname" name="firstname" placeholder="Your name..">

        <label for="lname">Last Name</label>
        <input type="text" id="lname" name="lastname" placeholder="Your last name..">

        <label for="email">Email</label>
        <input type="email" id="email" name="emailid" placeholder="example@company.com">
        </br>
        <label for="message">Description</label>
        <textarea id="message" name="subject" rows="6" cols="30" placeholder="Write something.." style="height:200px"></textarea>

        <input type="submit" value="Submit Details">
      </form>
    </div>

    </body>
    </html>

【问题讨论】:

  • 你在哪里 PHP 用于发送电子邮件的代码?
  • 同样的问题,您的 php 代码有问题,而不是 html,请分享您的 php 代码。
  • 你需要一些 php 代码来获取提交的数据并通过邮件发送。
  • 是的,在这里更新。请通过它。
  • 您通过 name` 属性而不是 id 属性访问表单值

标签: php email form-submit contact-form


【解决方案1】:

你需要改变:

<form action="your_name.php" method="POST">

并创建文件“your_name.php”,您可以在其中发布表单中的所有参数。 例如:

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$emailid = $_POST['emailid'];
$subject = $_POST['subject'];

如果你想将信息发送到已检查的电子邮件,你必须使用函数 mail() http://php.net/manual/ru/function.mail.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-04
    • 2019-06-30
    • 1970-01-01
    相关资源
    最近更新 更多