0

I want to do a "Contact Me" page. I have a problem as I am not receiving the email for testing. First, I used a localhost from my terminal with the following command:

php -S 127.0.0.1:8080

When I access the localhost:8080 the website works fine, but I am not receiving any emails from the contact me. Here is my HTML & php

HTML:

      <form class="contact-form" action="contactform.php" method="post">
        <input type="text" name="name" class="form-control" placeholder="Name" required><br>
        <input type="email" name="email" class="form-control" placeholder="Email" required><br>
        <textarea name="message" class="form-control" rows="4" placeholder="Message" required></textarea><br>
        <button type="submit" name="submit" class="form-control submit">SEND MESSAGE</button>
      </form>

PHP:

<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];

$mailTo = "monbay@inboxbear.com";
$subject = "Form Submission from ".$name;

mail($mailTo, $subject, $msg);
echo '<p>Your message has been sent!</p>';
}
?>
moe
  • 61
  • 6
  • You can't send email from localhost by default. – Tania Rascia Jul 08 '18 at 16:54
  • how can i test if my code functions properly then? – moe Jul 08 '18 at 16:55
  • There are chances that it could be in spam folder – hemnath mouli Jul 08 '18 at 16:55
  • did you change mail settings from php.ini ?? – Rumesh Jul 08 '18 at 16:58
  • @Rumesh i have not? – moe Jul 08 '18 at 17:00
  • refer this : https://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost – Rumesh Jul 08 '18 at 17:03
  • Do you have a mail server? Remember, `mail()` only passes a mail to a mail server, it does not actually send mail itself – RiggsFolly Jul 08 '18 at 17:08
  • You can either configure a mail sever for local delivery only - this may already be done - and then use email addresses like `yourusername@localhost`. Or you can configure some `sendmail` compliant utility or daemon to send mail out via your service provider and your account there, or gmail, or .... – ivanivan Jul 08 '18 at 17:14
  • Also take note that many mail providers have strict rules who may deliver mail to them. This usually excludes "private" consumer IP adresses from delivering mail, so testing from localhost is not possible. – Daniel Bürckner Jul 08 '18 at 17:42

0 Answers0