0

So I followed the following video to setup my email PHP form. I uploaded the form to my website to test it. I got the email in my spam inbox, but none of the data was sent (name, email, message, etc). I need help figuring out what I'm doing wrong.

HTML

<form action="mailDeveloper.php" method="POST">
            <p>Name:</p><input type="text" name="name" placeholder="John Smith" required autocomplete=""><br>
            <p>Email:</p><input type="email" name="email" placeholder="example@example.com" required autocomplete=""><br>
            <p>Subject:</p><input type="text" name="subject" placeholder="Support" required autocomplete=""><br>
            <p>Message:</p><textarea name="message" placeholder="Comments, questions, and anything else" required></textarea><br>
            <input type="submit" value="Submit">
        </form>

PHP

<?php

if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $mailFrom = $_POST['email'];
    $message = $_POST['message'];
}

$mailTo = "info@lpstories.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an email from ".$name.".\n\n".$message;

mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend") or die("There was an error, and your email did not send!");
?>
  • Does this answer your question? [Using if(isset($\_POST\['submit'\])) to not display echo when script is open is not working](https://stackoverflow.com/questions/7775512/using-ifisset-postsubmit-to-not-display-echo-when-script-is-open-is-not) – Greg Schmidt Jan 04 '20 at 05:58

1 Answers1

-1

Try below code as you missing headers : 
Missing Part
$headers ="Content-type:text/html;charset=iso-8859-1" . "\r\n";
    if(isset($_POST['submit'])) {
    $name       = $_POST['name'];
    $subject    = $_POST['subject'];
    $mailFrom   = $_POST['email'];
    $message    = $_POST['message'];
    $to         =  $mailFrom;    //brokeremail
    $from       =  "navalkishor2005@gmail.com";     //visitoremail
    $subject    =  "Sun Capital : Forgot Password";
    $logo       =  "";
    $messageRes = "";
    $messageRes.="<table align='center' width='490' style='font-family:Arial,Helvetica,sans-serif; background-color: rgb(255, 255, 255); border: 3px solid rgb(64, 64, 64); width: 610px;'>";
    $messageRes.="<tr>";
    $messageRes.="<td align='center' style='border: 2px solid rgb(65, 65, 65);background-color:#EDEDED'>";
    $messageRes.="<img src='$logo'></td></tr>";
    $messageRes.="<tr><td>&nbsp;</td></tr>";
    $messageRes.="<tr><td   >Dear Admin,</td></tr>";
    $messageRes.="<tr><td>User with following details contact you.</td></tr>";
    $messageRes.="<tr><td></td></tr>";
    $messageRes.="<tr><td>";
    $messageRes.="<table>";
    $messageRes.="<tr><td style='line-height: 24px; width: 160px;'><b>Name: </b></td><td>".$name."</td></tr>";
    $messageRes.="<tr><td style='line-height: 24px; width: 160px;'><b>Subject:</b>  </td><td> ".$subject."</td></tr>";
    $message.="<tr><td style='line-height: 24px; width: 160px;'><b>Message: </b></td><td>".$message."</td></tr>";
    $messageRes.="</table>";
    $messageRes.="</td></tr>";
    $messageRes.="<tr><td>&nbsp;</td></tr>";
    $messageRes.="<tr><td >Thank You,</td></tr>";
    $messageRes.="<tr><td >Support Team.</td></tr>";
    $messageRes.="</table>";
    $messageRes;
    $headers ="MIME-Version: 1.0" . "\r\n";
    $headers .="Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .="From: $from" . "\r\n";
    $abc=@mail($to,$subject,$messageRes,$headers);
    header("Location: index.php?mailsend") or die("There was an error, and your email did not send!");
    }
naval
  • 49
  • 5
  • 1
    Why? Why do you think this code will work, but OP's will not? As a side note, you probably should not post company names and email addresses here, I'd suggest editing and removing those details. – Don't Panic Jan 04 '20 at 10:23
  • As the person who need help did not include $headers .="Content-type:text/html;charset=iso-8859-1" . "\r\n"; and above code is tested and i am using this from last 8 years. – naval Jan 06 '20 at 07:23
  • 1
    I see now that you actually did explain that at the top of your answer, which was the whole point of my comment - answers need an explanation, not just code. I missed it because it is misformatted, and looks like just a big chunk of code. You could edit it to fix that and make your answer higher quality. – Don't Panic Jan 06 '20 at 09:51