Website contact form not working properly [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I am fairly new to coding and am having an issue with my website contact form. It won't allow me to receive email when the form is filled and submit button clicked.
I know nothing about PHP and it's obvious something is missing or incorrect. I've included only the relevant portions of the file...thanks for any help I can get!
<div id="page_4">
<div id="wrapper">
<form action="contact form.php" method="post">
<label for="fname">Name</label>
<input type="text" name="name" placeholder="Full name...">
<label for="email">Email</label>
<input type="text" name="email" placeholder="...">
<label for="phone">Phone</label>
<input type="text" name="phone" placeholder="...">
<label for="subject">Subject</label>
<input type="text" name="subject" placeholder="...">
<label for="detail">Project Detail</label>
<textarea name="detail" placeholder="Please use detail if possible..." style="height:200px"></textarea>
<label for="deadline">Project Deadline (MO/DY/YR)</label>
<input type="text" name="deadline" placeholder="...">
<input type="submit" value="Submit">
</form>
</div>
</div>
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailfrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "mark#markabove.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an e-mail from ".$name."\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.html?mailsend");
}
?>

The URL for the form action tag has a space in it. Perhaps change it to contact-form.php.

Related

HTML form showing the php code after submit

I have a simple html form what I use in all of my websites in different servers.
In a new server I found a problem I cant solve by my own.
The problem is that after hit the submit button php code doesnt send the email to the server email and doesnt direct to the thankyou.html page. But it does direct to mydomain.com/contactform.php and shows the php code. Firstly I though something wrong with the server configuration, but i didnt find anything. Could anyone give my any advice where to search? Thanks in advance!
PHP code:
<?php
if($_SERVER["REQUEST_METHOD"] === "POST") {}
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$place = $_POST['place'];
$number = $_POST['number'];
$csoportjelleg = $_POST['csoportjelleg'];
$message = $_POST['message'];
$recaptcha_secret = "secret-key";
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
$response = json_decode($response, true);
if($response["success"] === true){
$mailTo = "info#serveremail.com";
$headers = "From: ".$mailFrom;
$txt = "Feladó: ".$name."\nInnenjönnek: ".$place."\nLétszám: ".$number."\nCsoportjelleg: ".$csoportjelleg."\n\nÜzenet: ".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: thankyou");
}else{
header("Location: error");
}
}
?>
HTML code:
<form action="contactform.php" method="post" class="ajanlatkeres-form">
<h2 class="centered-h2">Általános adatok</h2>
<input type="text" name="name" placeholder="Teljes név*" class="feedback-input" required>
<input type="text" name="mail" placeholder="E-mail*" class="feedback-input" required>
<h2 class="centered-h2">További adatok</h2>
<input type="text" name="place" placeholder="Honnan jöttök?" class="feedback-input">
<input type="text" name="number" placeholder="Hány fős a csoport?" class="feedback-input">
<div class="feedback-input-div">
<p class="form-p">Csoport jelleg?</p>
<label class="container">Munkahelyi
<input type="radio" name="csoportjelleg" required>
<span class="checkmark"></span>
</label>
<label class="container">Iskolai
<input type="radio" name="csoportjelleg">
<span class="checkmark"></span>
</label>
<label class="container">Családi
<input type="radio" name="csoportjelleg">
<span class="checkmark"></span>
</label>
<label class="container">Egyéb
<input type="radio" name="csoportjelleg">
<span class="checkmark"></span>
</label>
</div>
<h2 class="centered-h2">Üzenet</h2>
<input type="hidden" name="subject" value="Csoportos ajánlatkérés">
<textarea name="message" placeholder="Ajánlatkérés üzenete:*" class="feedback-input" required></textarea>
<div class="g-recaptcha" id="rcaptcha" data-sitekey="6LdBDf4UAAAAAJ50InC0WKfVep4263x3Bmuz9-60"></div><br/>
<div class="button-form">
<button id="submit_form" class="contactbutton" type="submit" name="submit">Küldés</button>
</div>
UI.: PHP form location: I use thankyou and error without .html extension because there are no extensions in my ULR-s thanks to .htaccess manipulations. In other servers that was absolutly ok.
Updated, thanks kerbh0lz!

Why isn't my contact form PHP file working? [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I don't know much PHP but I used a tutorial to connect my contact form to my email. Below is my html contact form, and the PHP file I wrote:
<form name="contactform" method="post" action="mail.php">
<label for="fname">Name</label>
<input type="text" id="fname" name="name" placeholder="Your name..">
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="Your email address">
<label for="city">City</label>
<input type="text" id="city" name="city" placeholder="Your city">
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Write something.." style="height:170px">
</textarea>
<input type="submit" value="Submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$name = $_POST['name'];
$mailFrom= $_POST['email'];
$city = $_POST['city'];
$message = $_POST['message'];
$mailTo = "(insert my email here)";
$headers = "From: ".$mailFrom;
$txt = "You received an e-mail from ".$name.".\n\n"
mail($mailTo, $txt, $headers);
header("Location: " contact.html?mailsend");
}
?>
if (isset($_POST['submit']))
that will never be true, change it to any other field. name,email, city, message

Can't send mail through php in html [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm trying to develope a personal website as a projecet to one of my classes.
I don't understand much of html so i actually can't make my php work.
Please Help.
I've already tried copying and changing php codes from other fonts but nothing works...
This is the html code:
<div class="container">
<form action="" method="POST">
<input type="text" id="name" name="name" placeholder="Name">
<input type="text" id="email" name="email" placeholder="Email">
<textarea id="message" name="message" placeholder="Message" style="height:100px"></textarea>
<input type="submit" value="Send">
</form>
</div>
<form action="" method="POST">
<input type="text" id="name" name="name" placeholder="Name">
<input type="text" id="email" name="email" placeholder="Email">
<textarea id="message" name="message" placeholder="Message" style="height:100px"></textarea>
<input type="submit" name="submit" value="Send">
</form>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to_email = $email; // mail whom you want to send
$subject = ''; // your subject for sending email
$message = $name.' sent you message. <br><br>'.$message;
$headers = 'From: noreply#company.com'; // your mail id
mail($to_email,$subject,$message,$headers);
echo "This email is sent using PHP Mail";
}
?>
Use this above code, this will pass the name, email, message to mail function.
Hope this helps you.

PHP Online Form is not sending to Gmail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
Problem is when I submit this form it shows something went wrong. Could somebody check where I've made a mistake.
HTML code:
<div class="main">
<div class="info">Give your feedback</div>
<form action="mail.php" method="post" name="form" class="form-box">
<label for="name">Name</label><br>
<input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>
<label for="email">Email</label><br>
<input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>
<label for="phone">Phone</label><br>
<input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>
<input type="submit" name="submit" value="Send" class="sub-btn">
</form>
</div>
PHP code
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='onlyanivar#gmail.com';
$subject='Form Submission';
$message="Name:".$name."\n"."Phone:" .$phone. "\n"."Wrote the following: "."\n\n".$msg;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly</h1>";
}
else{
echo "Something went wrong!";
}
?>
You have no $headers variable declared when you call the mail function.

Bad conection between contact html and mail php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
CSS y PHP of my contact-form.
The page works perfectly but I'm trying to send an email and the button of send doesn't work. In the image you can see that when I try to send an email the button stays white. At the same time the button Clear works perfect! I attach my code
CONTACT.HTML
<form action="mail.php" method="POST" class="contact-form">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email address" class="contact-form-email required">
<input type="text" name="subject" placeholder="Subject" class="contact-form-subject">
<textarea name="message" placeholder="Message" class="required" rows="7"></textarea>
<div class="response-message"></div>
<button class="border-button" type="reset" id="reset" name="reset">Limpiar</button>
<button class="border-button" type="submit" id="submit" name="submit">Enviar</button>
MAIL.PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "sa*********#*******.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
mail function doesn't work on local server and also you need to set SMTP configuration in PHP to send mail.
Are you placing your form inside the form tag?
<form action="mail.php" method="post">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email address" class="contact-form-email required">
<input type="text" name="subject" placeholder="Subject" class="contact-form-subject">
<textarea name="message" placeholder="Message" class="required" rows="7"></textarea>
<div class="response-message"></div>
<button class="border-button" type="reset" id="reset" name="reset">Limpiar</button>
<button class="border-button" type="submit" id="submit" name="submit">Enviar</button>
</form>

Categories