jquery Remodal e-mail form - php

I'm using the Remodal plugin to show modals on my website. (https://github.com/VodkaBears/Remodal) This works great for my needs. This is the first time I'm working with modals and e-mail forms. I have a script to submit the form, and it looks like this;
<form name="contact" id="contact" class="contact" method="post">
<label for="name">
<span>Name</span>
<input type="text" name="name" required="true" />
</label>
<label for="email">
<span>Email</span>
<input type="email" name="email" required="true" />
</label>
<label for="phone">
<span>Phone</span>
<input type="text" name="phone" required="true" />
</label>
<label for="message">
<span>Your message</span>
<textarea name="message" required="true"> </textarea>
</label>
<label>
<br>
<span> </span>
<input type="submit" class="send" value="Send"/>
</label>
</form>
And this is my script for submitting the form;
$(document).on('click', '.send', function () {
$.ajax({
type: "POST",
url: "mail.php",
data: $('form.contact').serialize(),
success: function (msg) {
$("#thanks").html(msg)
$("form.contact").modal('hide');
},
error: function () {
alert("Error.");
}
});
return false;
});
Mail.php:
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "my#email.com";
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message = $_REQUEST['message'];
//send email
mail($admin_email, "New e-mail", $message, "From:" . $email);
//Email response
echo "Thank you!";
}
?>
I found this code somewhere, and I'm trying to implement it to my form. It works! However, I don't get any success message or error messages with this. I'm trying to wrap my head arond it, but can't figure it out. Can someone help?

Related

HTML form redirecting to PHP file when submitted?

I have an one-page website with a form in it. I am trying to show a "Thank you" message to replace the button "submit" after the form is filled. If that is possible? I want my page to be the same, but with the message, instead of the button.
Also, when I click "submit" the page is redirect to the PHP code, instead of just showing the message I want. Any ideas of what could be wrong?
HTML form:
<form action="envia_fale.php" method="post" id="form_" name="form_">
<input type="text" name="full_name" id="full_name" placeholder="Full Name" required>
<input type="email" name="email" id="email" placeholder="Email" required>
<input type="text" name="offer" id="offer" placeholder="Offer" required>
<input type="submit" id="send" name="send" value="SUBMIT">
</form>
PHP file:
<?php
if(isset($_POST['submit'])){
$to = "stefanicaguiar1993#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$full_name = $_POST['full_name'];
$subject = "OnlyPans.ie form submission";
$subject2 = "Copy of your form submission";
$message = "You have received a new offer from " . $full_name . "\n\n" . $_POST['offer'];
$message2 = "Here is a copy of your message " . $full_name . "\n\n" . $_POST['offer'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Email sent. Thank you " . $full_name . ", we will contact you shortly.";
}
?>
Try this out
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(function () {
$('#form_').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'envia_fale.php',
data: $('form').serialize(),
success: function () {
$('#send').replaceWith("<span>Send successfully</span>");
},
error: function (error) {
console.log(error)
}
});
});
});
</script>
</head>
<body>
<form id="form_" name="form_">
<input type="text" name="full_name" id="full_name" placeholder="Full Name" required>
<input type="email" name="email" id="email" placeholder="Email" required>
<input type="text" name="offer" id="offer" placeholder="Offer" required>
<input type="submit" id="send" name="send" value="SUBMIT">
</form>
</body>
</html>

Add form ID to JQuery form function

Im in need to create to separate e-mail forms based on AJAX and JQuery.
I need one form to be Standart and other VIP, when getting email from website - i need to indicate from which form customer has send inquiry.
I have sample form for Standard, and need to create VIP form. Imagine it is needed to create forms ID and insert it to JQuery.
Please help
Here is sample form code:
<form id="vip" class="pop_form" action="mail-vip.php">
<h4>ОPlease leave your contacs, we will come back soon!</h4>
<input type="text" name="name" placeholder="Name" required />
<input type="text" name="phone" placeholder="Telephone" required />
<input type="text" name="email" placeholder="E-mail" required />
<input type="text" name="time" placeholder="Callback time" />
<div align="center"><button type="submit">Send</button></div>
</form>
Jquery:
$("form").submit(function() {
$.ajax({
type: "GET",
url: "mail.php",
data: $("form").serialize()
}).done(function() {
alert("Спасибо за заявку!");
setTimeout(function() {
$.fancybox.close();
}, 1000);
});
return false;
});
PHP:
<?php
$recepient = "email;
$sitename = "Website";
$name = trim($_GET["name"]);
$phone = trim($_GET["phone"]);
$email = trim($_GET["email"]);
$email = trim($_GET["time"]);
$pagetitle = "New inquiry for \"$sitename\"";
$message = "Имя: $name \nTelephone: $phone \nE-mail: $email \nTime: $time";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");
?>
Thanks!!!
There are various way you can do that.
One of the way could be (minimal change to your code)
Add an hidden field in your form which will be automatically sent to your php and extract it to see it's type.
e.g. <input type="hidden" name="type" value="vip">
So it should look like,
<form id="vip" class="pop_form" action="mail-vip.php">
<h4>ОPlease leave your contacs, we will come back soon!</h4>
<input type="text" name="name" placeholder="Name" required />
<input type="text" name="phone" placeholder="Telephone" required />
<input type="text" name="email" placeholder="E-mail" required />
<input type="text" name="time" placeholder="Callback time" />
<input type="hidden" name="type" value="vip">
<div align="center"><button type="submit">Send</button></div>
</form>
form id is vip i think you need write $("#vip").submit
In the other word,the button where the type "submit " will also submit your form data ,so you don't need write the Ajax
query

No email received when sent with contact form

When I am filling out the contact form on the website that I am making, the e-mail will be sent, but I am not receiving it in the inbox of my computer.
The code looks like this:
HTML:
<div id="form">
<form action="mailto:psteintj#xs4all.nl" id="contactForm" method="post">
<span></span>
<input type="text" name="name" class="name" placeholder="Enter your name" tabindex=1 />
<span></span>
<input type="text" name="email" class="email" placeholder="Enter your email" tabindex=2 />
<span id="captcha"></span>
<input type="text" name="captcha" class="captcha" maxlength="4" size="4" placeholder="Enter captcha code" tabindex=3 />
<span></span>
<textarea class="message" placeholder="Enter your message" tabindex=4></textarea>
<input type="submit" name="submit" value="Send e-mail" class="submit" tabindex=5>
</form>
</div>
JS:
if ((captchaVal == captchaCode) && (emailFilter.test(emailText)) && (nameFilter.test(nameText)) && (messageText > 50)) {
$.post("mail.php", {
name: $(".name").val(),
email: $(".email").val(),
message:$(".message").val()
});
$("#contactForm").css("display", "none");
$("#form").append("<h2>Message sent!</h2>");
return false;
}
and PHP:
<?php
$name = $POST['name'];
$email = $_POST['email'];
$message = $POST['message'];
Could someone tell me where I am going wrong?
Well, you are not sending any emails (or at least you haven't posted any code about it), so of course you are not receiving any emails. You should configure the mailing, and use the mail function.
The function needs a working SMTP server to actually send out the e-mail.
Your PHP has no mail() call or similar? I'm probably missing something here.

unable to echo message sent in html page using php

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.

PHP form without opening a new window

Good day/evening. I have this sort of form in HTML:
<form action="scripts/form-testimonial.php" class="form" method="post">
<ul>
<li><label for="name">Name</label> <input class="required" id="namef3" name="name" placeholder="Name" type="text"></li>
<li><label for="email">E-mail</label> <input class="required" id="emailf3" name="email" placeholder="E-mail" type="text"></li>
<li><label for="company">Company</label> <input id="companyf3" name="company" placeholder="Company (if applicable)" type="text"></li>
<li><label for="msg">Message</label> <textarea class="required" cols="43" id="msgf3" name="msg" placeholder="Your feedback" rows="8"></textarea></li>
</ul>
<button class="submit" type="submit">Send your feedback</button>
</form>
and this sort of php sript for this form as a separate file:
<?php
$receip = "office#avehire.co.uk";
$subj = "Testimonial";
$bodymsg = "Name: ".$_POST['name']."\n"
."Company: ".$_POST['company']."\n"
."Email: ".$_POST['email']."\n"
."Message: ".$_POST['msg']."\n";
if(!$_POST['msg']){
header("Location: ../error.html");
exit;
}
$email = $_POST['email'];
if(mail($receip, $subj, $bodymsg, 'From: Contact <'.$email.'>')){
header("Location: ../msg_sent_feedback.html");
}
?>
I also have a validator for this form, but this is not important. What is more important here is the way how this form works. Basically - when you click submit button - it goes to a separate php file, process the form and then - from what is already there - goes to msg_sent_feedback.html file. What I want to do is to NOT opens a separate file but just display a message in the same basic html file where the actual form exists. A message e.g. "Message sent".
Another thing - if I already have a validation script - do I need to have the first "if" in this form? or can I remove it totally? the one which redirects to error.html. Or can I remove these 4 lines? That line - I guess - is responsible for errors in the form, but as I mentioned, I have a validation script. I don't really want to change html. is it possible to modify the php script to work within the html document, as instructed above? thanks
Here is an Jquery ajax example that will help you.
<?php
$receip = "office#avehire.co.uk";
$subj = "Testimonial";
$bodymsg = "Name: ".$_POST['name']."\n"
."Company: ".$_POST['company']."\n"
."Email: ".$_POST['email']."\n"
."Message: ".$_POST['msg']."\n";
if(!$_POST['msg']){
echo "<h1>Error sending e-mail";
exit;
}
$email = $_POST['email'];
if(mail($receip, $subj, $bodymsg, 'From: Contact <'.$email.'>')){
echo "<h1>Email sent successfully</h1>";
}
?>
Html :
<!Doctype html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function submitmyform(){
data=$('#myform').serialize();
$.ajax({
url: "myphpfile.php",
type:'POST',
data:data,
async:false,
dataType:'html',
success: function(msg){
$('#response_goes_here').html(msg);
}
});
}
</script>
<form action="" id="myform">
<ul>
<li> <label for="name">Name</label> <input id="namef3" name="name" type="text" placeholder="Name" class="required"/>
</li>
<li> <label for="email">E-mail</label> <input id="emailf3" name="email" type="text" placeholder="E-mail" class="required"/>
</li>
<li> <label for="company">Company</label> <input id="companyf3" name="company" type="text" placeholder="Company (if applicable)" />
</li>
<li> <label for="msg">Message</label> <textarea id="msgf3" name="msg" cols="43" rows="8" placeholder="Your feedback" class="required"></textarea>
</li>
</ul>
<button type="button" class="button" onclick="submitmyform();">Send your feedback</button>
</form>
<div id="response_goes_here"></div>

Categories