'PHP contact form configuration [duplicate]

Hi guys I run my website and it all work except contact us form. HTML

<div class="border"></div>
             <form class="contact-form" action="mail.php" method="post">

              <div class="fisrtthree">
              
              <input type="text" name="fname" class="contact-form-text" placeholder="First name" required>
              </div>

              <div class="fisrtthree">
              
              <input type="text" name="lname" class="contact-form-text" placeholder="Last name" required>
              </div>

              <div class="fisrtthree">
              
              <input type="email" name="email" class="contact-form-text" placeholder="Email" required>
              </div>

              <div>
              
              <textarea class="contact-form-text" name="message" rows="6" maxlength="3000" placeholder="Your message" required></textarea>
              </div>

              <div>
              <button type="submit" id="fcf-button" class="contact-form-btn">Send</button>
              <div>

             </form>

PHP

<?php
 if(isset($_POST['message']) == false) {     //  If there's no message
    echo "Uh oh. Looks like you didn't actually include a message, friend.<br><br>";
    die();   
}


$destination = "#@gmail.com";       //  Put your email address here
$subject = "Message from your website!";   //  Fill in the subject line you want your messages to have
$fromAddress = "#@domain.com";   //  Fill in the email address that you want the messages to appear to be from
                                                                //  Use a real address to reduce the odds of getting spam-filtered.
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$message = str_replace("\n.", "\n..", $_POST['message']);   //  Prevents a new line starting with a period from being omitted

$message = "First Name: ". $fname ."\n Last Name: ". $lname ."\n Email: ". $email ."\n Message: ".$message."\n";

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $fromAddress;
$headers[] = "Subject: " . $subject;
$headers[] = "X-Mailer: PHP/".phpversion();

mail($destination, $subject, $message, implode("\r\n", $headers));

Thanks for your message:
echo $message; ?>
Go back home ?>

As you see I tried to get message from #@domain.com and received it in [email protected]. but it didn't work, I received nothing in my inbox. is there anything to do with my gmail and my hosted email.



Solution 1:[1]

  1. Your email is not being sent. You can try to capture the error that happened via php's last error function, after sending the email : print_r(error_get_last());

Solution 2:[2]

Firstly, ensure that your email service provider makes allowance for the use of less secure apps, and make sure you have this feature enabled (Be sure to disable it later). My 'from' email was a Gmail account where non-secure apps can be enabled at this address: https://myaccount.google.com/lesssecureapps?pli=1

Secondly, ensure that your local mail server is correctly set up. If you are using XAMPP follow the directions here: https://www.geeksforgeeks.org/how-to-configure-xampp-to-send-mail-from-localhost-using-php/

Next, name the button on your form in order to detect the form submission, I named the button 'submit'. Then in mail.php use this code

<?PHP
if(isset($_POST['submit']) && empty($_POST['message'])) {     
//  If there's no message
echo "Uh oh. Looks like you didn't actually include a 
message, friend.<br><br>";
die();   
}

$destination = "[email protected]";
$subject = "Message from your alfidomain.com!";
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$fromAddress=$email;
$message = str_replace("\n.", "\n..", $_POST['message']);   
//  Prevents a new line starting with a period from being omitted

$message = "First Name: ". $fname ."\n Last Name: ".$lname ."\n Email: ". $email ."\n Message: ".$message."\n";

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $fromAddress;
$headers[] = "Subject: " . $subject;
$headers[] = "X-Mailer: PHP/".phpversion();

mail($destination, $subject, $message, implode("\r\n", 
$headers));

// mail($to,$subject,$msg,$headers);
echo "Email successfully sent.";
?>

If you are not Abdelali make sure you set $destination to "[email protected]"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Lwandile Rozani