html :
View/contactform.html
<form method="post" role="form" name="myemailform" action="sendingemail.php">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" cols="10" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<div class="text-center"><input type="submit" class="btn applyBtn" name="submit"/></div>
</form>
PHP:
view/sendingemail.php
<?php
$name = $_POST['name'];
$email_from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$emails = "From: $email_from \r\n";
$emails .= "Name: $name \r\n";
$emails .= "Message: $message \r\n";
mail('sunitha_anilkumar#yahoo.com',$subject,$emails);
echo 'Mail sent!';
header('Location: thank-you.html');
?>
app.js
.when('/contactus', {
templateUrl: 'view/contactform.html',
controllerAs:'vm'
})
I wanted a contact form in my angular project and I given the form in view/contactform.html and sendingemail.php for submitting the form details. But when I submit the form, i am just seeing the sendingemail.php code , no form submission is done.Need assistance.
This means your webserver does not recognise your php file to be run as a php file. You might want to check your webserver's documentation to install and/or enable the PHP module.
Related
I´m tring to add a success message to my form after you click submit, but i dont know how, i have tried different code from different websites, but they dont work with my code. What line do i need to add to this code please?
<form action="contact.php" method="post" id="contact">
<h1>Contact-me!</h1>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="name">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="name#example.com">
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea name="message" class="form-control" id="message" rows="3"></textarea>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary mb-3" value="SEND MESSAGE">Submit</button>
<div>
</div>
</div>
</form>
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = '';
$email_subject = "New Form Submission";
$email_body = "User Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: index.html");
?>
I've been having trouble with PHP (new to php) to clear my form fields AFTER a successful submission. I would also like to show an alert that it was successful. Any ideas? Using javascript with the onclick listener for the submit button will not work because it clears the fields before PHP has time to send the data.
Here is my html:
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-strech" data-aos="fade-left">
<form id="contact-form" action="contact-form-handler.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 characters"/>
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Email</label>
<input type="email" name="email" class="form-control" id="email" data-rule="email" data-msg="Please enter at valid email"/>
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter a subject of at least 8 characters"/>
<div class="validate"></div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please enter a message"></textarea>
<div class="validate"></div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
Here is my PHP:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = "Portfolio Email";
$email_body = "Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$email_to = "email#gmail.com";
$headers = "From: $email_from \r\n";
mail($email_to, $subject, $email_body);
?>
If you do not want to use ajax, please try the following
(assuming the html is known as "form.html", and the php is "contact-form-handler.php")
The php redirection to form.html will clear the input fields (a normal behavior in web-browsers), and the javascript will show the word "successful" as an alert.
Please make further adjustment(s) according to your needs.
form.html
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-strech" data-aos="fade-left">
<form id="contact-form" action="contact-form-handler.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 characters"/>
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Email</label>
<input type="email" name="email" class="form-control" id="email" data-rule="email" data-msg="Please enter at valid email"/>
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter a subject of at least 8 characters"/>
<div class="validate"></div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please enter a message"></textarea>
<div class="validate"></div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
<script>
function get(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
</script>
<script>
if (get("result")=="success")
{
alert("Successful");
}
</script>
contact-form-handler.php
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = "Portfolio Email";
$email_body = "Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$email_to = "email#gmail.com";
$headers = "From: $email_from \r\n";
mail($email_to, $subject, $email_body);
?>
<script>
window.location.href="form.html?result=success"
</script>
Hi there im building a website and looking to connect a contact form to send an email/ message to an email address and im not quite sure what im doing wrong.
I'm very new so apologies and thank you in advance..
here's the code i have below!
PHP
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = 'tomasyoung0#gmail.com';
$headers = 'From: '.$mailFrom;
$txt = 'You have received an e-mail from '.$name.'. \n\n'.$message;
mail($mailTo, $subject, $txt, $headers);
header('Location: index.html?mailsend')
?>
HTML
<form class="contact-form" action="contactform.php" method="POST">
<input class="form-input" name="name" type="text" placeholder="Name" >
<input class="form-input" name="email" type="email" placeholder="Email">
<input class="form-input" name="subject" type="text" placeholder="Subject" >
<textarea class="form-input" placeholder="Message" cols="30" rows="10"></textarea>
<button class="btn"type="submit" name="submit">
<div class="button">
<i class="fa fa-paper-plane"></i><span class="send-text"></span>
</div>
</button>
</form>
You don't have mail and message at your html code, change
<input class="form-input" name="email" type="email" placeholder="Email">
To
<input class="form-input" name="mail" type="email" placeholder="Email">
And
<textarea class="form-input" placeholder="Message" cols="30" rows="10"></textarea>
To
<textarea class="form-input" name = "message" placeholder="Message" cols="30" rows="10"></textarea>
Inside [] of post variable you must put name of your input or button inside [] using ''
I cant seem to figure out what the problem is with my code. After pressing submit it will redirect to a error page and says "This page isn’t working website is currently unable to handle this request. HTTP ERROR 500"
HTML
<div class="container">
<form action="contact.php" method="POST" class="form">
<div class="form-group">
<label for="name" class="form-label">Your Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Jane Doe" tabindex="1" required>
</div>
<div class="form-group">
<label for="email" class="form-label">Your Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="jane#doe.com" tabindex="2" required>
</div>
<div class="form-group">
<label for="subject" class="form-label">Subject</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Hello There!" tabindex="3" required>
</div>
<div class="form-group">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" rows="5" cols="50" id="message" name="message" placeholder="Enter Message..." tabindex="4"></textarea>
</div>
<div>
<button type="submit" class="btn">Send Message!</button>
</div>
</form>
</div>
PHP
<?php
$message_sent = false;
if(isset($_POST['email]') && $_POST['email'] != ''){
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ){
$userName = $_POST['name'];
$userEmail = $_POST['email'];
$messgeSubject = $_POST['subject'];
$message = $_POST['message'];
$to = "email"
$body = "";
$body .= "From: ".$userName. "\r\n";
$body .= "Email: ".$userEmail. "\r\n";
$body .= "Message: ".$message. "\r\n";
mail($to,$messgeSubject,$body);
$message_sent = true;
}
}
?>
there is an typing error in your php (line no 3).. you have written
isset($_POST['email]'
it should be
isset($_POST['email'])
I have a running form and it's half working. The form sends to my email address correctly but i'm having issues with the inputs not showing the text in the email. The only one that spits out any data is the message section.
The name, email, phone and website inputs are not spitting out any data and I can't figure out why?
// html5 code
<form action="forms/get_form.php" method="post">
<div>
<label for="name">Name</label>
<input type="text" id="name" placeholder="enter name" required="required">
</div>
<div>
<label for="email">Email</label>
<input type="email" id="email" placeholder="email address" required="required">
</div>
<div>
<label for="phone">Phone Number</label>
<input type="tel" id="phone" placeholder="enter phone number" required="required">
</div>
<div>
<label for="website">Enter website URL if you have one (optional)</label>
<input type="url" id="website" placeholder="website address">
</div>
<div>
<label for="message">Enter your message</label>
<textarea name="message" id="message" rows="10"></textarea>
</div>
<div>
<button type="submit" class="btn-blue">Send</button>
</div>
</form>
// php code
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Website: $website \n Message: $message";
$recipient = "email goes here";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader);
if(mail) {
header('Location: /thankyou.html');
} else {echo "Email failed to send click back and check email details!";}
?>
Thanks in advance
Vizzy
Not ID but NAME param,
<input type="text" id="name" placeholder="enter name" required="required">
Should be:
<input type="text" name="name" placeholder="enter name" required="required">
Instead of ID, use name.
<input type="text" name="name" placeholder="enter name" required="required">