Reputation: 73
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";
}
}
}
?>
Upvotes: 0
Views: 99
Reputation: 66
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.
Upvotes: 1