0

フォームに入力したメールアドレス以外の情報が記載されたメールを受信できており、メールを受信すると人の名前ではなく「送信者なし」と表示されます。私は PHP を初めて使用し、いくつかの Google 検索を実行しましたが、何が間違っているのかわかりません。助けてください。ありがとう

これは私のHTMLです:

<?php include("parts/doctype.php"); ?>

<?php include("parts/header.php"); ?>   

<div class="page-wrap">

    <?php include("parts/nav.php"); ?>  

        <div class="page-grid">

            <h1 class="site-section-title">Contact Us</h1>

            <div class="content-area">

                <form action="send-mail.php" method="POST">

                    <div class="contactName">
                        <h1 class="heading Name">Name</h1>
                        <label for="first-name" class="first_name">First Name</label>
                        <input type="text" id="first_name" name="first_name"  placeholder="Jane" autofocus required>
                        <label for="last_name" class="last_name">Last Name</label>
                        <input type="text" id="last_name" name="last_name" placeholder="Doe" required>
                    </div> <!-- end name -->

                    <div class="number">
                        <h1 class="heading">Phone Number</h1>
                        <label for="number" class="phone">Phone number</label>
                        <input type="tel" id="number" pattern="[0-9]{10}" name="sender_phone" placeholder="(###)-###-####">
                    </div> <!-- end number -->

                    <div class="email">
                        <h1 class="heading">Email Address</h1>
                        <label for="email" class="emailLabel">Email</label>
                        <input type="email" name="sender_email" placeholder="janedoe@gmail.com" required>
                    </div>

                    <div class="message">
                        <h1 class="heading">Message</h1>
                        <label for="message"></label>
                        <textarea name="sender_message" id="message" cols="30" rows="10" spellcheck="true" required> </textarea>
                    </div>

                    <button id="submit" class="send">Send</button>

                </form>

            </div> <!-- end content area -->

        </div> <!-- end grid -->

    </div> <!-- end page wrap -->

そして、これは私のPHPです:

<?php
$mail_to = 'removed address but I know it goes here'; // specify your email here

// Assigning data from the $_POST array to variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$message = $_POST['sender_message'];

// Construct email subject
$subject = 'Its time for a cupcake Message from visitor ' . $first_name;

// Construct email body
$body_message = 'From: ' . $first_name . $last_name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";  
$body_message .= 'Message: ' . $message;

// Construct email headers
$headers = 'From: ' . $first_name . "\r\n";

$headers .= 'Reply-To: ' . $mail_from . "\r\n";

$mail_sent = mail($mail_to, $subject, $body_message, $headers);


if ($mail_sent == true){ ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you for the message. Should your message require a responce we will get back to you shortly.');
    window.location = 'contactus.php';
    </script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
    alert('Message not sent. Please, try your message again. Should this still not work please contact use through facebook or twitter both links located on our home page.');
    window.location = 'index.php';
</script>
<?php
}
?>
4

1 に答える 1