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!
Related
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.
I'm trying to get a contact form working, and I'm being redirected to the PHP file itself, and I'm not sure why. I'm fairly new to PHP and I'm not entirely sure what I'm doing wrong. I'd love to be pointed in the right direction. The code is below.
Thanks
HTML:
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
PHP:
<?php
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
?>
This line tells the form what PHP file to send the data to:
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
In particular, it is this part that sends the data to a particular form:
action="form.php"
In fact, this is fine. You can process a form in the same PHP file that contains the form. Just put the PHP form processing at the top:
<?php
if (isset($_POST['Email_Address'] && $_POST['Email_Address'] != ''){
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
Just remove enctype="text/plain" otherwise your code is correct in HTML and try to echo feedback variable other way is to write all your code above the HTML like below:
<?php
if (isset($_POST['Email_Address'] && !empty['Email_Address']){
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
Hi guys i'm having a issue i hope you guys can help with, i'm typing in all the fields and then upon pressing submit i'm getting just "Error!" on my screen.
Please see the code:
HTML
<h2 class="formhead">Contact Form</h2>
<br>
<form class="form" action="mail.php" method="POST">
<p class="name">
<input type="text" name="name" id="name" placeholder="John Doe" />
<label for="name">Name</label>
</p>
<br>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" />
<label for="email">Email</label>
</p>
<br>
<p class="number">
<input type="text" name="number" id="number" placeholder="0774XXXXXXX" />
<label for="name">Contact Number</label>
</p>
<br>
<p class="web">
<input type="text" name="web" id="web" placeholder="www.example.co.uk" />
<label for="name">Website</label>
</p>
<br>
<p class="message">
<textarea name="message" id="message" placeholder="Write something to us" /> </textarea>
</p>
<br>
<p class="submit">
<input type="submit" value="Send"/>
</p>
</form>
PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$website = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries#c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
Any help would be much appreciated!
Thanks
Sam
Your script always reporting 'Error!' because the mail() function always fails. That's because some index you're using in the php file doesn't match to the input names in your form:
Change these:
$website = $_POST['website'];
to:
$website = $_POST['web'];
Or change it in your form.
Also you have to specify a name for the message textarea:
<textarea name="message" id="message" placeholder="Write something to us" />
This may fail again if it can't connect to mailserver. This is probably you're case if The SMTP is Disabled.
As per my comment, here's an example of a better die statement:
<?
$your_function or die("Error! a") // Just replace the letter a with anything. It serves as a simple link to your function that only you know. so you can go back and check it
I currently have this page I am working on:
http://www.webauthorsgroup.com/new/template/index3.html
In the lower right corner is a form (php), but I can't "echo" a text message after it has been submitted (for whatever reason).
My form is:
<form id="contact" method="post" action="">
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required">
<label for="email">E-mail</label>
<input name="hidden" class="required email" onblur="if(value=='<?php echo htmlentities($_POST['email']); ?>') value = 'Your Email'" onfocus="if(value=='Your Email') value = ''" type="email" value="Your Email" placeholder="yourname#domain.com">
<label for="phone">Phone</label>
<input name="phone" onblur="if(value=='<?php echo htmlentities($_POST['phone']); ?>') value = 'phone'" onfocus="if(value=='phone') value = ''" type="tel" value="phone" placeholder="ex. (555) 555-5555">
<input type="hidden" name="phone" placeholder="ex. (555) 555-5555">
<label for="message">Question/Comment</label>
<textarea name="message" onblur="if(value=='<?php echo htmlentities($_POST['message']); ?>') value = 'message'" onfocus="if(value=='message') value = ''" value="message" placeholder="Message"></textarea>
<input type="submit" name="submit" class="button" id="submit" value="Send Message" />
</fieldset>
</form>
=========================================================
the process.php is:
<?php
if(isset($_POST['submit']))
{
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$url = strip_tags($_POST['url']);
$message = strip_tags($_POST['message']);
echo "Thank You!";
}
// Send Message
mail( "bruce#webauthorsgroup.com", "Inquiry From WebAuthorsGroup",
"Name: $name\nEmail: $email\nPhone: $phone\nWebsite: $url\nMessage: $message\n",
"From: Forms <forms#example.net>" );
?>
=================================================
I need the "message sent" text echoed in the same div after submitting the form and I don't want to convert my index page to index.php
Any help would be great!
The PHP code on the page index3.html is not being parsed or executed by the PHP interpreter on your server because the file extension is .html. Go ahead and view source on that page in the browser. Note that you can see the PHP code. You should not be able to see PHP code in the HTML source. You should see only the HTML rendered by the PHP. Please change the file extension to .php so your server can execute it instead of outputting it as text.
I'd greatly appreciate some help with my PHP contact form. I've followed a number of tutorials to try and get this working and I am still without luck. The code is as follows.
N.B. I am using styling elements defined within the Twitter Bootstrap Framework and the form appears in a modal-style popup (although I can't see why this would affect the form).
Is there anything else I might have to activate/configure on my hosting side apart from having PHP enabled.
FORM CODE:
<form method="POST" action="mail.php">
<fieldset>
<input type="text" name="first_name" placeholder="First Name">
<input type="text" name="last_name" placeholder="Last Name">
<input type="email" name="email" placeholder="Email Address">
<div class="controls controls-row">
<input type="date" name="check_in" placeholder="Check in Date"><span class="help-inline">Check-in</span>
</div>
<div class="controls controls-row">
<input type="date" name="check_out" placeholder="Check out Date"><span class="help-inline">Check-out</span>
</div>
<input type="number" name="rooms" min="1" max="7" placeholder="Number of Rooms">
<input type="number" name="occupants" min="1" max="14" placeholder="Number of Occupants">
<textarea rows="3" name="additional" input class="input-xparge" placeholder="Additional requirements" class="span5"></textarea>
</fieldset>
<div class="modal-footer">
<button type="submit" input type="submit" id="submit" class="btn btn-block btn-large btn-success" value="submit">Submit</button>
</div>
</form>
PHP CODE:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$check_in = $POST['check_in'];
$check_out = $POST['check_out'];
$rooms = $POST['rooms'];
$occupants = $POST['occupants'];
$additional = $_POST['additional'];
$from = "From: $first_name";
$to = "lloyd.rees09#bathspa.ac.uk";
$subject = "New Booking Enquiry";
$body = "First Name: $first_name\n Last Name: $last_name\n Email: $email\n Check In: $check_in\n Check Out: $check_out\n Number of Rooms: $rooms\n Number of Occupants: $occupants\n Additional Information: $additional";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
Thank you kindly in advance!
don't you need to add name="submit" to the 'button' tag?
in your php, you are testing 'if ($_POST['submit']) {'
and $_POST['submit'] might not being getting set without name="submit" in that tag