I'm trying to send email with PHP using an Ajax request, but my "echo" on the PHP file just seems to not work and I have no idea why.
Thinking that my PHP code was wrong, I replaced my code with just an "echo" as posted below, but it still is not working.
I'm posting my HTML, JS, PHP and also the firebug response, which I don't quite understand.
HTML
<form id="contactForm" class="contact-form">
<div class="form-group form-icon-group">
<input class="form-control" id="name" name="name" placeholder="Nome" type="text" required title="Por favor, preencha esse campo." x-moz-errormessage="Por favor, preencha esse campo."/>
<i class="fa fa-user"></i>
</div>
<div class="form-group form-icon-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required title="Por favor, preencha esse campo corretamente." x-moz-errormessage="Por favor, preencha esse campo corretamente.">
<i class="fa fa-envelope"></i>
</div>
<div class="form-group form-icon-group">
<textarea class="form-control" id="message" name="message" placeholder="Qual sua mensagem?" rows="10" required title="Por favor, preencha esse campo." x-moz-errormessage="Por favor, preencha esse campo."> </textarea>
<i class="fa fa-pencil"></i>
</div>
<div>
<a id="btnEnviar" value="Enviar Email" class="btn btn-primary btn-lg">Enviar Email</a>
</div>
<div>
<label id="labelResposta" style="font-size: 22px; margin-top: 20px; display: none;">Email enviado com sucesso!</label>
</div>
<div id="messages"></div>
</form>
JS
$('#btnEnviar').click(function() {
$('#btnEnviar').html('Enviando...');
$('#btnEnviar').attr('disabled', 'disabled');
var formData = {
nome: $('#name').val(),
email: $('#email').val(),
message: $('#message').val()
};
// console.log(formData);
// console.log($("#contactForm").serialize());
if(!formData.nome) {
$('#btnEnviar').html('Enviar Email');
$('#btnEnviar').removeAttr('disabled');
$('#labelResposta').html('Por favor preencha seu nome.');
$('#labelResposta').fadeIn();
setTimeout(function() {
$('#labelResposta').fadeOut();
}, 3000);
} else if(!formData.email) {
$('#btnEnviar').html('Enviar Email');
$('#btnEnviar').removeAttr('disabled');
$('#labelResposta').html('Por favor preencha seu email.');
$('#labelResposta').fadeIn();
setTimeout(function() {
$('#labelResposta').fadeOut();
}, 3000);
} else if(!formData.message) {
$('#btnEnviar').html('Enviar Email');
$('#btnEnviar').removeAttr('disabled');
$('#labelResposta').html('Por favor preencha sua mensagem.');
$('#labelResposta').fadeIn();
setTimeout(function() {
$('#labelResposta').fadeOut();
}, 3000);
} else {
$.ajax({
url: 'file:///home/phellipe/Desktop/projetos/phperin/email/email_processor.php',
type: "POST",
data: formData,
success: function(data) {
$('#btnEnviar').html('Enviar Email');
$('#btnEnviar').removeAttr('disabled');
$('#labelResposta').html('Email enviado com sucesso!');
$('#labelResposta').fadeIn();
setTimeout(function() {
$('#labelResposta').fadeOut();
}, 3000);
},
error: function(x, e){
console.log(x);
console.log(e);
if(x.status==0){
$('#labelResposta').html('Você não está online!\n Por favor, verifique sua conexão.');
}else if(x.status==404){
$('#labelResposta').html('URL não encontrada.');
}else if(x.status==500){
$('#labelResposta').html('Erro interno.');
}else if(e=='parsererror'){
$('#labelResposta').html('Erro de parse.');
}else if(e=='timeout'){
$('#labelResposta').html('Timeout.');
}else {
$('#labelResposta').html('Erro desconhecido.\n'+x.responseText);
}
$('#btnEnviar').html('Enviar Email');
$('#btnEnviar').removeAttr('disabled');
$('#labelResposta').fadeIn();
setTimeout(function() {
$('#labelResposta').fadeOut();
}, 3000);
}
});
}
return false;
});
PHP (test)
<?php echo "string"; ?>
PHP (real)
<?php
$sender_name = trim(ucfirst($_REQUEST['nome']));
$sender_email = trim($_REQUEST['email']);
$sender_message = trim(ucfirst($_REQUEST['message']));
$html_email = '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PhPerin</title>
</head>
<body>
<p>Olá</p>
<p>Notificamos que <em>' . $sender_name . '</em> entrou em contato</p>
<p>Deixou a seguinte mensagem:</p>
<p>' . $sender_message . '</p>
<p>Você pode entrar em contato pelo seguinte email ' . $sender_email . '</p>
</body>
</html>';
require_once("send_email.php");
echo "string";
?>
Firebug Response
readyState 4
responseText "<?php echo "string"; ?>"
status 200
statusText "parsererror"
I wonder if you need to escape those double quotes. Where it says
<meta charset="UTF-8">
try
<meta charset=\"UTF-8\">
Related
I have a form script that sends an email after its been submitted. A javascript removes the form after its been submitted.
But when I submit my form it shows me the empty .php file.
Heres my index.html code:
<!--Here is container with email subscription-->
<div class="container-fluid yellow-container bg-mail">
<div class="row-fluid">
<div class="span12">
<h2>Laat hier je email adres achter, zodat wij weten dat je van de partij bent</h2>
<p>Deze uitnodiging geldt voor jou en een relatie!</p>
<form action="save.php" id="subscribe-form" method="post" name="subscribe-form">
<input type="email" name="email" placeholder="Hier je emailadres" id="email" class="email required">
<button class="btn btn-inverse" id="submit" type="submit" value="Subscribe">Count me in!</button>
</form>
</div>
</div>
</div>
save.php code:
<?php
if (isset($_POST['email'])) {
//Email information
$admin_email = "marco#daretodesign.nl";
$email = $_POST['email'];
//send email
mail($admin_email, "Inschrijving via Dukdalf", $email . " " . "heeft zich ingeschreven via de website", "Van:" . $email);
}
?>
javascript code:
//Subscribe Form
if($('#subscribe-form').length && jQuery()) {
$('form#subscribe-form').submit(function() {
$('form#subscribe-form .error').remove();
var hasError = false;
$('.required').each(function() {
if(jQuery.trim($(this).val()) === '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Vul a.u.b. uw email in.'+labelText+'</div>');
$(this).addClass('inputError');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(jQuery.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Vul a.u.b. een geldig email in.'+labelText+'</div>');
$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError) {
$('form#subscribe-form input.submit').fadeOut('normal', function() {
$(this).parent().append('');
});
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#subscribe-form').slideUp("fast", function() {
$(this).before('<div class="error">Bedankt voor het inschrijven!</div>');
});
});
}
return false;
});
Thanks for help in advance :)
it shows you your blank php page because you after send email should redirect user to somewhere, perhaps with:
header('Location: http://www.example.com/');
exit;
Regards,
Marcelo
I have a kind of a quiz running soon, where the answers are shown and should be submitted via email.
The script uses a sendmessage.php which runs fine for "answer one". All other answers, despite the pages being absolutely equal (except for the text) dont.
This is the correct page "one":
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" media="all" href="style.css">
<link rel="stylesheet" type="text/css" media="all" href="fancybox/jquery.fancybox.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="fancybox/jquery.fancybox.js?v=2.0.6"></script>
</head>
<body>
<H2><br />
</H2>
<div id="wrapper">
<d>Der größte Fan</d><br>
<br>
<p>Du liebst alles, was mit Schönheit zu tun hat!
Warum teilst du nicht deine Leidenschaft für Mary Kay® Produkte mit deiner Familie und deinen Freunden?
Du kannst nicht verbergen, wie du dich damit fühlst – gepflegt, selbstbewusst und schön!<br>
</div>
<div id="wrapper">
Schick uns dein Ergebnis, und erhalte die Einladung zur Facebook-Gruppe!</p>
<p><a class="modalbox" href="#inline">Ergebnis ans Mary Kay<sup>®</sup> Büro schicken</a> </p>
</div>
<!-- hidden inline form -->
<div id="inline">
<h2>Schick uns dein Ergebnis</h2>
<form id="contact" name="contact" action="#" method="post">
<label for="cons">Deine Consultantnummer</label>
<input type="cons" id="cons" name="cons" maxlength="8" class="txt"><br>
<label for="name">Dein Name & nbsp; </label>
<input type="name" id="name" name="name" class="txt"><br>
<label for="email">Deine Email </label>
<input type="email" id="email" name="email" class="txt">
<br>
<label for="msg">Mein Ergebnis lautet:</label>
<textarea id="msg" name="msg" class="txtarea" readonly>Der größte Fan. Du liebst alles, was mit Schönheit zu tun hat!
Warum teilst du nicht deine Leidenschaft für Mary Kay® Produkte mit deiner Familie und deinen Freunden?
Du kannst nicht verbergen, wie du dich damit fühlst – gepflegt, selbstbewusst und schön! </textarea>
<button id="send">Email abschicken</button>
</form>
</div>
<!-- basic fancybox setup -->
<script type="text/javascript">
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9] {1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(mailvalid == true && msglen >= 4) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>wird verschickt...</em>");
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Super! Deine Ergebnisse sind zu uns unterwegs! Vielen Dank :)</strong></p>");
setTimeout("$.fancybox.close()", 5000);
});
}
}
});
}
});
});
</script>
</body>
</html>
The sendmesaage is as follows:
<?php
$sendto = "me#myaddress.com";
$username = $_POST['name'];
$usercons = $_POST['cons'];
$usermail = $_POST['email'];
$fromfield = "online_formular#myaddress.com";
$content = nl2br($_POST['msg']);
$subject = "Ein Quiz wurde ausgefüllt";
$headers = "From: " . strip_tags($fromfield) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Ein Quiz wurde ausgefüllt</h2>\r\n";
$msg .= "<p><strong>Absender:</strong> ".$username."</p>\r\n";
$msg .= "<p><strong>Cons.-Nr.:</strong> ".$usercons."</p>\r\n";
$msg .= "<p><strong>Email:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Nachricht:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";
if(#mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
?>
That combination works - all files in the same directory.
When I use the second answer (two.html) - it doesnt do anything... it states that is was sent, but it will never arrive.
Two:
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" media="all" href="style.css">
<link rel="stylesheet" type="text/css" media="all" href="fancybox/jquery.fancybox.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="fancybox/jquery.fancybox.js?v=2.0.6"></script>
</head>
<body>
<H2><br />
</H2>
<div id="wrapper">
<d>Die Netzwerkerin</d><br>
<br>
<p>
Deine Freunde sind dir am wichtigsten. Deshalb ist für dich ein Geschäft perfekt, das es dir ermöglicht, mehr Zeit mit deinen Freundinnen zu verbringen und gleichzeitig neue Freundschaften aufzubauen.
<br>
</div>
<div id="wrapper">
Schick uns dein Ergebnis, und erhalte die Einladung zur Facebook-Gruppe!</p>
<p><a class="modalbox" href="#inline">Ergebnis ans Mary Kay<sup>®</sup> Büro schicken</a></p>
</div>
<!-- hidden inline form -->
<div id="inline">
<h2>Schick uns dein Ergebnis</h2>
<form id="contact" name="contact" action="#" method="post">
<label for="cons">Deine Consultantnummer</label>
<input type="cons" id="cons" name="cons" maxlength="8" class="txt"><br>
<label for="name">Dein Name </label>
<input type="name" id="name" name="name" class="txt"><br>
<label for="email">Deine Email </label>
<input type="email" id="email" name="email" class="txt">
<br>
<label for="msg">Mein Ergebnis lautet:</label>
<textarea id="msg" name="msg" class="txtarea" readonly>Die Netzwerkerin. Deine Freunde sind dir am wichtigsten. Deshalb ist für dich ein Geschäft perfekt, das es dir ermöglicht, mehr Zeit mit deinen Freundinnen zu verbringen und gleichzeitig neue Freundschaften aufzubauen.</textarea>
<button id="send">Email abschicken</button>
</form>
</div>
<!-- basic fancybox setup -->
<script type="text/javascript">
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(mailvalid == true && msglen >= 4) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>wird verschickt...</em>");
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Super! Deine Ergebnisse sind zu uns unterwegs! Vielen Dank :)</strong></p>");
setTimeout("$.fancybox.close()", 5000);
});
}
}
});
}
});
});
</script>
</body>
</html>
If anyone has any suggestions, that would be awesome!
Thanks in advance,
Dimitri
I'm with a doubt,
I'm trying sending data to my database but it doesn't insert it them. How can i put them to send it?
index.php (script part):
<div id="wel">
<p id="title-call">Junta-te <font color="gray">a nós!</font></p><hr color="#c96308" noshadow />
<p id="subx">Percorre este mundo e torna-te o treinador número <font color="#c96308">UM</font>!</p>
</div>
<div id="loading"><br /></div>
<div id="warn2"><br /></div>
<div id="success"><br /></div>
<div id="subscribe">
<form id="sub" action="" method="POST" >
<input type="text" name="username" id="username" placeholder="Escreve aqui o teu Nome..." /><br />
<br />
<input type="text" name="email" id="email" placeholder="Escreve aqui o teu E-mail..." /><br /><br />
<input type="submit" id="submit" value="Subscrever" />
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#sub").submit(function() {
if($("#username").val()==""||$("#email").val()=="") {
$("#warn2").hide(36000);
$("#loading").css("display:inline");
$("#loading").html("<img src='images/ajax-loader.gif' width='1%' height='3%' /> A carregar...");
$("#loading").fadeIn(200);
$("#loading").fadeOut(200);
$("#warn2").css("display:none");
$("#warn2").html("Por favor escreve o teu nome e/ou email!<br />");
$("#warn2").hide(36000);
$("#warn2").fadeIn(1000);
$("#warn2").css("display:inline");
$("#warn2").fadeOut(7000);
}
else {
var s = $("#sub").serializeArray();
$.ajax({
url: "subscribe.php",
method: "POST",
data: s,
success: function() {
$("#success").css("display:none");
$("#success").hide(36000);
$("#loading").css("display:inline");
$("#loading").html("<img src='images/ajax-loader.gif' width='1%' height='3%' /> A carregar...");
$("#loading").fadeIn(200);
$("#loading").fadeOut(200);
$("#success").css("display:none");
$("#success").html("A tua subscrição foi efectuada com successo!");
$("#success").hide(36000);
$("#success").fadeIn(1000);
$("#success").css("display:inline");
$("#success").fadeOut(7000);
}
});
}
return false;
});
$("#MGa").click(function() {
$("#hidGames").css("display: inline");
$("#hidGames").fadeToggle(1000);
return false;
});
$("#MGa").mouseover(function() {
$("#arrow").html('<img src="images/arrow_wbm_hover.png" width="1%" height="1%" />');
});
$("#MGa").mouseout(function() {
$("#arrow").html('<img src="images/arrow.png" width="1%" height="1%" />');
});
$("#arrow").html('<img src="images/arrow.png" width="1%" height="1%" />');
});
</script>
subscribe.php :
<?php
include_once('db.php');
$username = $_POST["username"];
$email = $_POST["email"];
$date = date("Y-m-d h:i:s:A");
$sql = mysql_query("INSERT INTO subscribers VALUES('','$username','$email','$date')");
// mail function //
$to = $email;
$header = "From: info#wbm.pt";
$header. = "Content-Type: text/html;";
$subject = "Bem-vindo ao WBM!";
$body = "
Bem vindo ao WBM (World Basket Manager) <b>$username</b>,<br />
<br />
Sê o treinador número <i>UM</i> deste mundo de treinadores.<br />
- Cria a tua equipa;<br />
- Compra e Vende jogadores;<br />
- Calendário real;<br />
- Equipas Originais (NBA);<br />
- Estádios;<br />
- Forma as tuas próprias táticas;<br />
<br>
Tudo isto no mundo de treinadores de basquetbol!<br />
Lançamento da versão BETA:<br />
<b>Data prevísivel: <i>25 de Maio de 2014</i></b><br />
<br />
Muito Obrigado,<br />
<b>Equipa WBM</b>
<br />
<br />
<h6>Não responder a este e-mail!</h6>
";
// mail //
mail($to,$header,$subject,$body);
$rw = mysql_query("SELECT * FROM subscribers");
$rows = mysql_num_rows($rw);
if($rows!=0) {
$nrow = $rows;
}
else {
}
$to1 = "cell phone number";
$header1 = "From: 15030#wbm.pt";
$header1. = "Content-Type: text/play;";
$subject1 = "Bem-vindo ao WBM!";
$body1 = "
Têm $nrow que se subscreveram.
Muito Obrigado.
(Não responder a esta mensagem)
";
//sms to my cell phone //
mail($to1,$header1,$header1.,$subject1,$body1);
?>
db.php:
<?php
$connect = mysql_connect('localhost','root','');
mysql_select_db('subscribers');
?>
What can I do to this thing work guys?
You need to be checking for mysql errors, that would give you a big clue.
$query = "INSERT INTO subscribers VALUES('','$username','$email','$date')";
$sql = mysql_query($query) or throw new Exception("Query Failed: {$query}. Error: ".mysql_error());
Your code is open to SQL Injection, you should really be using MySQLi or PDO at this point, and if you're going to stick with mysql, escape your data.
I am trying to add a change password function on my site. I decided that i would try using ajax so the site does not have to update itself. But i have one problem. When i submit the form to my PHP file nothing happends i just get the success from the ajax file. And the password is not change in my SQL db.
This is the html file.
<div class="boxPW">
<div class="boxInner">
<img class="closeBox" style="float: right;" src="images2/zoom/closebox.png" />
<h2>Endre passord ditt</h2>
<div id="lineBreak" style="margin-top: -19px; width: 70%;"></div>
<h4>Skriv inn et nytt passord for <?php echo $fname.' '.$lname.' ';?>
Vi anbefaler at du oppretter et unikt passord –
et du ikke bruker på noen andre nettsteder. <h4>
<div class="boxInner2">
<form id="changePw" name="changePw" method="POST" action="">
<input type="password" id="oldPw" name="oldPw" placeholder="Nåværende passord" />
<label id="error_oldPw" class="error">Fyll inn nåværende passord</label>
<p style="margin: 0; width:100px; font-size:9px; color: #38C6DA; ">Glemt ditt passord?</p>
<div class="divider"></div>
<input type="password" id="newPw" name="newPw" placeholder="Nytt passord"/>
<label id="error_newPw" class="error">Fyll inn nytt passord</label>
<div class="divider"></div>
<input type="password" id="conNewPw" name="conNewPw" placeholder="Bekreft nytt passord"/>
<label id="error_conNewPw" class="error">Gjenta ditt passord</label>
<div class="divider"></div>
<input id="buttonpw" class="button" type="button" name="submit" value="Endre passord" />
</form>
</div>
</div>
</div>
And here are my Jquery file (returnPwBox.js)
$(document).ready(function() {
$('.error').hide();
$('#buttonpw').click(function(){
//Validate inputData
$('error').hide();
var oldPw = $("input#oldPw").val();
if(oldPw == ""){
$("label#error_oldPw").show();
$("input#oldPw").focus();
return false;
}
var newPw = $("input#newPw").val();
if(newPw == ""){
$("label#error_newPw").show();
$("input#newPw").focus();
return false;
}
var conNewPw = $("input#conNewPw").val();
if(conNewPw != newPw){
$("label#error_conNewPw").show();
$("input#conNewPw").focus();
return false;
}
var dataString = 'oldpw='+ oldPw + '&newPw=' + newPw + '&conNewPw=' + conNewPw;
$.ajax({
type: "POST",
url: "changePw.php",
data: dataString,
success: function(){
$('.boxInner2').html("<div id='message' style='width: 300px;'></div");
$('#message').html("<h2>Endring fullført</h2>")
.append("<h4>Ditt passord er nå endret</h44>")
.hide()
.fadeIn(1000, function(){
$('#message').append("<img id='checkmark' src='imgaes2/pitcharrow.gif'/>");
});
}
});
return false;
});
And here are my changePw.php:
<?php
include('conn.php');
require_once('auth.php');
include('fetchMemData.php');
function clean($str){
$str=#trim($str);
if(get_magic_quotes_gpc());{
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$id=$_SESSION['SESS_MEMBER_ID'];
$oldPw = clean($_POST['oldPw']);
$newPw = clean($_POST['newPw']);
$conNewPw = clean($_POST['conNewPw']);
$oldPw = strip_tags($oldPw);
$newPw = strip_tags($newPw);
$conNewPw = strip_tags($conNewPw);
$oldPw = md5($oldPw);
$newPw = md5($newPw);
$conNewPw = md5($conNewPw);
if($oldPw == $password)
{
mysql_query("UPDATE reguser SET password='$newPw' WHERE mem_id='$id'");
}else{
echo ("Feil nåværende passord");
}
?>
If anyone see any errors or any suggestions, shout out! I need some help:)
Based on the code you wrote $password value is not asigned (unless you did it in another file) therefore $password is NULL , and the if:
if($oldPw == $password)
{
mysql_query("UPDATE reguser SET password='$newPw' WHERE mem_id='$id'");
}else{
echo ("Feil nåværende passord");
}
returns false
I'm french (sorry for the english) and I'm looking for a solution to this problem.
I made a form witch send a mail to the adress I indicate in the contact.php file.
The problem is that the mail I receive does not contain the "emailSchool" variable.
Here are some of my files :
My html file :
<div id="formulaire">
<form id="myForm" action="contact.php" method="post">
<label for="emailName">Nom et prénom:</label>
<input name="emailName" type="text" id="emailName"/>
<label for="emailFrom">Email:</label>
<input name="emailFrom" type="text" id="emailFrom"/>
<label for="emailSchool">Ecole :</label>
<input name="emailSchool" type="text" id="emailSchool"/>
<label for="emailMessage">Message: (optionnel)</label>
<textarea name="emailMessage" cols="30" rows="9" id="emailMessage"></textarea>
<input style="padding-left:5px; width:80px; height:32px;" type="image" src="images/send.png" id="submit" class="submit" alt="ENVOYER"/>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
My script :
$("#submit").click(function(){
var hasError = false;
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
var emailFromVal = $("#emailFrom").val();
if(emailFromVal == '') {
$("#emailFrom").addClass("error");
hasError = true;
} else if(!emailReg.test(emailFromVal)) {
$("#emailFrom").addClass("error");
hasError = true;
}
else
{
$("#emailFrom").removeClass("error");
}
var nameVal = $("#emailName").val();
if(nameVal == '') {
$("#emailName").addClass("error");
hasError = true;
}
else
{
$("#emailName").removeClass("error");
}
var schoolVal = $("#emailSchool").val();
if(schoolVal == '') {
$("#emailSchool").addClass("error");
hasError = true;
}
else
{
$("#emailSchool").removeClass("error");
}
var messageVal = $("#emailMessage").val();
if(messageVal == '') {
$("#emailMessage").addClass("error");
hasError = true;
}
else
{
$("#emailMessage").removeClass("error");
}
if(hasError == false) {
$(this).hide();
$("#myForm").fadeOut("fast", function(){
$("#myForm").before('<img src="images/loading.gif" alt="Loading" id="loadingImage" />');
$.post("contact.php", { emailFrom: emailFromVal, emailName: nameVal, emailSchool: schoolVal, emailMessage: messageVal },
function(data){
$("#loadingImage").fadeOut("fast", function() {
$("#loadingImage").before('<p>Votre inscription a bien été pris en compte, nous vous enverrons un email pour confirmer !</p>');
});
}
);
});
}
return false;
}
And my .php file :
<?php
$nameVal=$POST['emailName'];
$emailFromVal=$POST['emailFrom'];
$messageVal=$POST['emailMessage'];
$schoolVal=$POST['emailSchool'];
$to='mymail#gmail.com';
$sujet='Nouvel incrit JEIC CHALLENGE !'.$emailFrom;
$msg='Message :'.$emailMessage;
$mailHeader = "From = {$emailFrom}";
$mailBody = "Nom = {$emailName} Ecole = {$emailSchool}";
mail($to, $sujet, $msg, $mailBody , $mailHeader);
?>
The problem is that I don't have the "School" field in the mail I receive.
Maybe somebody have a solution ?
Thanks a lot.
You are defining:
$schoolVal=$POST['emailSchool'];
And using in your header:
$emailSchool
Maybe change {$emailSchool} into {$schoolVal} ....
You mix POST names and locals...