Unable to send mail from the inquiry form created in PHP

Asked 2 years ago, Updated 2 years ago, 93 views

I'm a beginner at PHP, but I can't reach gmail even if I press the send button.I checked the spam, but there was no spam.
I give it to xserver using docker.Why can't I send an email?
I look forward to hearing from you.

index.php

<form action="contact.php" method="POST">
    <div class="form-content pt-5">
        <div class="form-left">
            <div class="form-group">
                <input type="text" class="form-control" name="name
                " placeholder = "Name" >
            </div>
            <div class="form-group mt-5">
                <input type="text" class="form-control" name="email
                " placeholder = "Email Address" >
            </div>
        </div>
        <div class="form-right">
            <div class="form-group">
                <textarea class="form-control" name="message
                " placeholder="Contact Us" rows="10"></textarea>
            </div>
        </div>
    </div>
    <p><input type="submit" value="Send with above" class="wpcf7-form-control wpcf7-submit text-center"id="button">/p>
</form>

contact.php

<?php
echo 'hello';
if(isset($_POST['submit'])){
    $name = $_POST ['name'];
    $emailFrom=$_POST['email'];
    $message=$_POST ['message'];

    $mailTo="[email protected]";
    $headers="From:".$mailFrom;
    $txt = "You have received an e-mail from n.$name. ..\n\n".$message;

    mail($mailTo,$txt,$headers);
    header("location:contact.php?mailsend");        
}

php html

2022-09-30 21:48

1 Answers

on the contact.php side
if(isset($_POST['submit'])){

There is a conditional branch, but the submit button on the submit form on the index.php side is

<input type="submit" value="Send with above" class="wpcf7-form-control wpcf7-submit text-center" id="button">

The name attribute does not exist.This is probably because $_POST['submit'] is not always set.So

<input type="submit" name="submit" value="Send with above" class="wpcf7-form-control wpcf7-submit text-center"id="button">

You can do it as


2022-09-30 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.