Call PHP form from HTML - html

contact-form.html
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
contact-form-handler.php
<?php
$errors = '';
$myemail = 'net.dev#spikyarc.net';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
This both file i have put in wwwroot folder but when i submit html form it gives error The page cannot be displayed. I cannot find problem. Thanks for helping me.

set the action in the HTML form to:
contact-form-handler.php
like:
<form method="POST" name="contactform" action="contact-form-handler.php">
UPDATE 1: And check this:
Change
$email_subject = "Contact form submission: $name";
to
$email_subject = "Contact form submission:" . $name;
UPDATE 2: And this also:
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
to:
$headers = "From: " . $myemail . "\n";
$headers .= "Reply-To:" . $email_address;
UPDATE 3:
You validate the E-mail address $email_address but never use it.

Be sure to check the filename with that in the action!!

Related

How to notification show after Form successful submit

I change my website template. i change Contact Form also previous contact form work correctly, when i change contact form template than submit form successful notification dont show under submit button. i checked all details but i can not find any error. help me this form.
form code
<form class="contact-form" id="contact-form" method="post" action="sendemail.php">
<div class="form-group tiple">
<input type="text" class="contact-box" name="name" value="" placeholder="Enter Your Name">
</div>
<div class="form-group tiple">
<input type="email" class="contact-box" name="email" value="" placeholder="Enter Your Email">
</div>
<div class="form-group tiple">
<input type="text" pattern="[6|7|8|9][0-9]{9}" class="contact-box" name="phone" value="" placeholder="10 Digit Mobile No.">
</div>
<div class="form-group">
<label>Subject</label>
<select name="subject" class="form-control">
<option value="Demo Registraion">Demo Registraion</option>
<option value="Contact Us">Contact Us</option>
<option value="Feedback">Feedback</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<textarea name="message" class="contact-box" placeholder="Your Message" rows="10"></textarea>
</div>
<button type="submit" class="short-line margin-top-10">Submit now</button>
</form>
sendmail.php code
<?php
// Define some constants
define( "RECIPIENT_NAME", "NAME" );
define( "RECIPIENT_EMAIL", "mail#email.com " );
// Read the form values
$success = false;
$senderName = isset( $_POST['name'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\#a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$senderPhone = isset( $_POST['phone'] ) ? preg_replace( "/[6|7|8][0-9][9]/", "", $_POST['phone'] ) : "";
$subject = isset( $_POST['subject'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['subject'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
// If all values exist, send the email
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$mailBody = 'Sender Name: ' . $senderName. "\r\n" . 'Sender Email: ' . $senderEmail . "\r\n" .'Sender Phone: '. $senderPhone . "\r\n" . 'Subject: ' . $subject . "\r\n" . 'Message: ' . $message;
$success = mail( $recipient, $subject, $mailBody, $headers );
echo 'Your Request Send Successful';
echo "<p class='success'>Thanks for contacting us. We will contact you ASAP!</p>";
?>
i want an notification under the submit button
msg submit successfull or failed
You can follow PRG pattern and use RedirectAttributes to add flash attributes.
For example:
#RequestMapping(value = "/contractor", method = RequestMethod.POST)
public String handle(#Valid #ModelAttribute Contractor contractor,
BindingResult result,
RedirectAttributes redirectAttributes) {
// Save contactor ...
redirectAttributes.addFlashAttribute("message", "Successful!");
return "redirect:/someGetUrl";
}
And just show this message in the view rendered by /someGetUrl handler.

Email send with "mailto" not showing in my gmail inbox HTML

I made a form where you could fill out some details and when you clicked "send" it sent to your email, It worked fine for me but people told me they clicked send but i didn't see anything in my inbox, I hope someone got a solution, Thanks
<form action="MAILTO:myemail#gmail.com?subject= Intro request" method="post" enctype="text/plain">
Just use PHP to send email:
HTML form for email input:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
<input type="email" name="email" class="form-control" required="required" placeholder="Email address">
<textarea name="message" id="message" required="required" class="form- control" rows="8" placeholder="Message"></textarea>
<button type="submit" id="submit" class="btn btn-danger btn-lg">Send Message</button>
</form>
When the submit button is clicked, the form will be sent to the server to be processed by php script below.
sendEmail.php:
$name = $_POST['name'];
$email = $_POST['email'];
$subject = 'query';
$message = $_POST['message'];
$email_from = $email;
$email_to = 'myemail#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = mail($email_to, $subject, $body, 'From: visitor');
Hope this helps

css is lost when form is submitted

Form
<form method="post" action="php/contactengine.php">
<ul>
<li><label for="Name">Name:</label></li>
<li><input type="text" name="Name" id="Name" /></li>
</ul>
<ul id="Surname">
<li><label for="Surname">Surname:</label></li>
<li><input type="text" name="Surname" id="Surname" /></li>
</ul>
<ul>
<li><label for="Town">Town:</label></li>
<li><input type="text" name="Town" id="Town" /></li>
</ul>
<ul>
<li><label for="Tel">Mob/Tel:</label></li>
<li><input type="text" name="Tel" id="Tel" /></li>
</ul>
<ul>
<li><label for="Email">Email:</label></li>
<li><input type="text" name="Email" id="Email" /></li>
</ul>
<ul>
<li><label for="Message">Message:</label><br /></li>
<li><textarea name="Message" rows="30" cols="20" id="Message"></textarea></li>
</ul>
<input type="submit" name="submit" value="Submit" class="submit-button" />
<input type="reset" name="reset" value="Clear" class="reset-button" /></form>
Engine
<?php
$EmailFrom = "enquiry#madisonjacob.co.uk";
$EmailTo = "james#madisonjacob.co.uk";
$Subject = "Website communication - MadisonJacob";
$Name = Trim(stripslashes($_POST['Name']));
$Surname = Trim(stripslashes($_POST['Surame']));
$Town = Trim(stripslashes($_POST['Town']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-error.php\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Town: ";
$Body .= $Town;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
if(isset($_POST['Surame']) && $_POST['Surname'] == '') {
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
}
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-thanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-error.php\">";
}
?>
...
Having issues with the contact form just going to the error page without any css showing. Think I've broken it somewhere too using some suggestions (my fault i'm sure).
Do I have to force a refresh on initial load with a counter so that it doesn't keep on reloading (if so how is best to do this please)?
If it's just that I'm not using the best code above then please correct me thanks.
Surname is a hidden field (hidden by css) to stop bots using the form.
All help much appreciated.
Could you please post your full code? Rest i feel you must use
document.location.href = 'contact-thanks.php';
for redirection.

On button event send an mail in html

I'm using the following HTML:
<div>
<form method="post" action="mailto:hr#kine.com" >
<input type="submit" value="Send Email" />
</form>
</div>
However, when I try and load the page, I get the following error:
No webpage was found for the web address
Why does this happen, and how can I fix this?
Try below code to send email using php & html
<div>
<form method="post">
<input type="submit" name='submit' value="Send Email" />
</form>
</div>
<?php
if(isset($POST['submit']){
$to = 'hr#kine.com';
$subject = 'Website Change Reqest';
$headers = "From: test#example.com\r\n";
$headers .= "Reply-To: test#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = 'Test Email';
$message .= '<h1>Hello, World!</h1>';
mail($to, $subject, $message, $headers);
}
?>
I hope it can help you.

Send completed form information to an email

Hey guys I'm just starting to learn some php and I was wondering how I could send information from a completed form to an email. I have the code I have listed on the bottom but I know it's not right, any help will be appreciated thanks!
PHP:
<?php
$email = $_REQUEST['clientEmail'] ;
$subject = "New Order";
$name = $_REQUEST['clientName'] ;
$articleAmount = $_REQUEST['articleNum'];
$wordAmount = $_REQUEST['wordNum'];
$topic = $_REQUEST['topic'];
$info = $_REQUEST['addInfo'];
mail("kevin.duan996#gmail.com", $subject,
"Name:" . $name . "<br/>" . "Amount of Articles:" . $articleAmount . "<br/>" . "Amount of Words:" . $wordAmount . "<br/>" . "Topic:" . $topic . "<br/>" . "Additional Information:" . $info, "From:" . $email);
echo "Thank you for ordering!";
?>
html:
<form action="order.php">
<fieldset id="client" >
<legend>Client Information</legend>
<label for="clientName">Name:</label><input type="text" name="clientName" id="clientName" tabindex="1"/>
<label for="clientEmail">Email:</label><input type="email" name="clientEmail" id="clientEmail" tabindex="2"/>
</fieldset>
<fieldset id="order">
<legend>Order Information</legend>
<label for="articleNum">Number of Articles</label><input type="text" name="articleNum" id="articleNum" tabindex="3"/>
<label for="wordNum">Words per Article</label><input type="text" name="wordNum" id="wordNum" tabindex="4"/>
<label for="topic">Topics</label><input type="text" name="topic" id="topic" tabindex="5"/>
<label for="addInfo">Additional Info</label><input type="text" name="addInfo" id="addInfo" tabindex="6"/>
</fieldset>
<fieldset>
<button type="submit">Submit!</button>
</fieldset>
</form>
Use PHP mail or PHPMailer (works pretty well) ?
Using the PHPMailer library: https://github.com/PHPMailer/PHPMailer
define('PROJECT_ROOT', '/path/to/your/root/'); //Different for different webhosts or self hosted environments
require (PROJECT_ROOT . 'PHPMailer-master/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$to = $_POST['clientEmail']; //Email dervied from POST data.
$mail->Host = "mail.example.com"; //If you haven't got an SMTP server, use Gmail's free one.
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Username = "someEmail#example.com";
$mail->Password = "somePass";
$mail->From = 'someEmail#example.com';
$mail->FromName = 'My Website';
$mail->WordWrap = 50;
$mail->isHTML(true); // Or false
$mail->addReplyTo('support#example.com', 'Support');
$mail->Subject = 'Message subject here';
$mail->addAddress($to);
$mail->Body = ""; // Message body using HTML here. (Remove if $mail->isHTML(); is false)
$mail->AltBody = "
Client: " . $_POST['clientName'] . " //Again: derived from POST data.
Email: " . $to . " //We defined this variable before as clientEmail
Number of Articles: " . $_POST['articleNum'] . "
Words per Article: " . $_POST['wordNum'] . "
Topics: " . $_POST['topic'] . "
Additional Info: " . $_POST['addInfo'] . "
";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
echo "Mail sent!";
}
I noticed that your form is missing a method of sending this information that the users type in.
<form action="order.php">
It should be:
<form action="order.php" method="POST">
Hope that you get it working!