-1

My contact form in php doesnt send the message to the mail so i need to know whats the problem here You will find the html form here with file name : index.php and php form with name : mail.php

<form class="form" action="mail.php" method="post" name="contactform">
    <input class="name" type="text" placeholder="Name" name="name">
    <input class="email" type="email" placeholder="Email" name="email" >
    <input class="phone" type="text" placeholder="Phone No:" name="phone">
    <textarea class="message" id="message" cols="30" rows="10" placeholder="Message"name="message"  ></textarea>
    <input class="submit-btn" type="submit" value="Submit">
</form>

<?php
if (isset($_POST['submit']) ) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $from = 'From:  phone'; 
    $to = 'modysaid26@gmail.com'; 
    $subject = 'message';

    $body = "From: $name\n E-Mail: $email\n Phone Number: $phone\n Message:\n $message";

    if (isset($_POST['submit'])) {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been submitted</p>';
        } else { 
            echo '<p>Something went wrong, please try again!</p>'; 
        }
    }
}
?>
Yulio Aleman Jimenez
  • 1,642
  • 3
  • 17
  • 33
  • Try add the $email to $from. Here is a similar contact form that it works: https://coursesweb.net/php-mysql/simple-contact-form-script – CoursesWeb Mar 24 '19 at 05:40

3 Answers3

0
<input class="submit-btn" name='submit' type="submit" value="Submit">

You are missing to add the name to submit button so your case if (isset($_POST['submit']) ) { fails

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0

you dont need to put name on the form tag remove the class either: <form action="mail.php" method="post">

0

First yor submit button name is missing, please use a

<input class="submit-btn" type="submit" value="Submit" name="submit">

The second you email command ( mail ($to, $subject, $body, $from) ) has no right email header. Insead your $from please define header with following parameters

$email_headers = "From: ".$from_name." <".$from_email.">\r\n".
"Reply-To: ".$reply_to."\r\n" ;
if ($cc) $email_headers.="Cc: ".$cc."\r\n";
if ($bcc) $email_headers.="Bcc: ".$bcc."\r\n";
$email_headers.="MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";

$email_body=$_POST['message'];

and then send it using

mail($to, $subject, $email_body, $email_headers);

And then your email shouldbe send properly.

uxmal
  • 428
  • 1
  • 7
  • 17