0

I using simple form for input to send email with php script during execution of web shows me script php error with all php code I am using https://replit.com how can I fix this problem

<html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link rel="preload" href="script.js" as="script">
    <link rel="reload" href="email.php" as="script">
  </head>
  <body>
<div id="form-container">
<form action="email.php" id="form1" method="post">
<label class="fname">Your Name</label><br>
<input id="fname" type="input" name="fname"></input><br>
<label class="pnum">Phone</label><br>
<input id="pnum" type="input" name="pnum"></input><br>
<button id="subbttn" type="submit" onclick="test1()">Submit</button>
</form>
<?php
   if(isset($_POST["submit"])){
   $fname =$_POST['fname'];
   $pnum =$_POST['pnum'];
   $to='[email protected]';
   $header = "From:[email protected]. \r\n";
   $subject='form Submission';
   $message="Name:".$fname "phone" .$pnum;
  if (!mail($to, $subject, $message, $headers)) {
       echo "Sending Failed";
   }
      else{
          echo "Your Message has been send";
      }
       }
   }
   ?>
1
  • If there is an error in the output, it's worth adding this to the question as it helps understand the problems. Commented Jun 15, 2021 at 7:10

1 Answer 1

1

Possible solution:

<form action="THIS FILE.php" id="form1" method="post">
<label for="fname" class="fname">
Your Name
<input id="fname" type="input" name="fname">
</label>
<label for="pnum" class="pnum">
Phone
<input id="pnum" type="input" name="pnum">
</label>
<button id="subbttn" type="submit" onclick="test1()">Submit</button>
</form>

Add the php code below at the top of the page.

<?php if($_SERVER['REQUEST_METHOD'] == "POST"){

$fname = $_POST['fname'];
$pnum = $_POST['pnum'];
$to = '[email protected]';
$header = "From:[email protected]. \r\n";
$subject ='form Submission';
$message = "Name: ".$fname." Phone: ".$pnum;

   if(mail($to, $subject, $message, $headers)){
      echo "Mail has been send";
   }else{
      echo "Mail has not been send";
   }
}
?>

I changed your if mail statement, because the mail function can be executed and your mail will be send.

But if it can't be executed in what way so ever it wont send.

forget the include/require

I hope this works.

Sign up to request clarification or add additional context in comments.

2 Comments

jazzy where you want me to put Require ("email.php");
well if it is an external script you have to require it on top of the page. but i think it's the same script. so then you don't have to require it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.