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
Related
So I have a chatting site in PHP, but the problem is that anyone can access any "chatroom". Is there a way to add an "Enter passcode" text box to the site before they are able to access the real thing? And if possible I would prefer not using those JavaScript pop-ups. And for the people who really want to help, I don't need any CSS.
My code:
index.php:
<?php
session_start();
if(isset($_GET['logout'])){
//Simple exit message
$logout_message = "<div class='msgln'><span class='left-info'>User <b class='user-name-left'>". $_SESSION['name'] ."</b> has left the chat session.</span><br></div>";
file_put_contents("log.html", $logout_message, FILE_APPEND | LOCK_EX);
session_destroy();
header("Location: ../../index.php"); //Redirect the user
}
if(isset($_POST['enter'])){
if($_POST['name'] != ""){
$_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
}
else{
echo '<span class="error">Please type in a name</span>';
}
}
function loginForm(){
echo
'<div id="loginform">
<p>Please enter your name to continue!</p>
<form action="index.php" method="post">
<label for="name">Name —</label>
<input type="text" name="name" id="name" />
<input type="submit" name="enter" id="enter" value="Enter" />
</form>
</div>';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> Chat</title>
<meta name="description" content=" Chat Application" />
<link rel="stylesheet" href="../../css/chat.css" />
</head>
<body>
<?php
if(!isset($_SESSION['name'])){
loginForm();
}
else {
?>
<div id="wrapper">
<div id="menu">
<p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?></b></p>
<p class="logout"><a id="exit" href="#">Exit Chat</a></p>
</div>
<div id="chatbox">
<?php
if(file_exists("log.html") && filesize("log.html") > 0){
$contents = file_get_contents("log.html");
echo $contents;
}
?>
</div>
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" />
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
</form>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function () {
$("#submitmsg").click(function () {
var clientmsg = $("#usermsg").val();
$.post("post.php", { text: clientmsg });
$("#usermsg").val("");
return false;
});
function loadLog() {
var oldscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height before the request
$.ajax({
url: "log.html",
cache: false,
success: function (html) {
$("#chatbox").html(html); //Insert chat log into the #chatbox div
//Auto-scroll
var newscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height after the request
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
}
});
}
setInterval (loadLog, 2500);
$("#exit").click(function () {
var exit = confirm("Are you sure you want to end the session?");
if (exit == true) {
window.location = "index.php?logout=true";
}
});
});
</script>
</body>
</html>
<?php
}
?>
post.php:
<?php
session_start();
if(isset($_SESSION['name'])){
$text = $_POST['text'];
$text_message = "<div class='msgln'><span class='chat-time'>".date("g:i A")."</span> <b class='user-name'>".$_SESSION['name']."</b> ".stripslashes(htmlspecialchars($text))."<br></div>";
file_put_contents("log.html", $text_message, FILE_APPEND | LOCK_EX);
}
?>
I've looked up other questions with possible solutions to my problem, but they don't seem to work for me.
According to the Network console in Firefox, my contact form sends GET when I set the method to POST.
I have checked my HTML code for errors, but can't find any; no unclosed forms, divs, etc. I've checked the syntax for my php, too.
I also tried setting the submit button to <button type="submit" formmethod="post" formaction="form-to-email.php" name="submit" class="button">Und los</button>'but it doesn't help, either.
EDIT: Here's my complete HTML code for this page:
<!DOCTYPE html>
<html lang="" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="placeholder">
<meta name="keywords" content="placeholder">
<meta name="author" content="placeholder">
<title>MADesign.</title>
<link rel="author" href="robots.txt" />
<link rel="author" href="humans.txt" />
<!-- CSS -->
<link rel="stylesheet" href="css/maincss.css">
</head>
<body>
<div id="holder">
<!-- page header -->
<div class="bg-image-small">
<div id="main_menu">
<header id="page_header">
<img src="images/mad-logo-300px.png" alt="mad logo" id="mad-logo">
</header>
<!-- END page header -->
<!-- main navigation -->
<nav id="main-nav">
<ul>
<li>home</li>
<li>link1</li>
<li>link2</li>
<li>link3</li>
<li>kontakt</li>
<li>impressum</li>
</ul>
</nav><!-- END main navigation -->
</div><!-- END main menu -->
</div><!-- END background image -->
<!-- main content -->
<main>
<!-- contact form -->
<form id="my-form" name="myForm" action="/form-to-email.php" method="post">
<h2>Let's get in touch.</h2>
<p>Schick mir eine Email an abc#placeholder.de oder nutze mein Kontaktformular.</p>
<div class="gender">
<input type="radio" name="titles" value="male" id="mr"
<?php if($titles == "male") echo "checked" ?>>
<label for="titles">Herr</label>
<input type="radio" name="titles" value="female" id="mrs"
<?php if($titles == "female") echo "checked" ?>>
<label for="titles">Frau</label>
<input type="radio" name="titles" value="nonbinary" id="mx"
<?php if($titles == "nonbinary") echo "checked" ?>>
<label for="titles">Hallo</label>
<input type="radio" name="titles" value="person" id="person"
<?php if($titles == "person") echo "checked" ?>>
<label for="titles">Person</label>
<div class="errormsg">
<?php echo $errors['titles']; ?>
</div>
</div>
<div class="form-block">
<label for="usrname">Name:</label><br>
<input type="text" name="usrname" id="usrname" class="styleinput" size="20" maxlength="30" value="<?php echo htmlspecialchars($usrname) ?>">
<div class="errormsg">
<?php echo $errors['usrname']; ?>
</div>
</div>
<div class="form-block">
<label for="email">Email:</label><br>
<input type="text" name="email" id="email" class="styleinput" size="20" maxlength="30" value="<?php echo htmlspecialchars($email) ?>">
<div class="errormsg">
<?php echo $errors['email']; ?>
</div>
</div>
<div class="user-input form-block">
<label for="user-input">Nachricht:</label><br>
<textarea class="styleinput" id="message-me" name="usrmsg" rows="4" cols="50" value="<?php echo htmlspecialchars($usrmsg) ?>"></textarea>
<div class="errormsg">
<?php echo $errors['usrmsg']; ?>
</div>
</div>
<button type="submit" formmethod="post" formaction="/form-to-email.php" name="submit" class="button">Und los</button>
<input type="reset" name="reset" class="button" value="Nochmal neu..." onclick="emptyMsg()">
<div id="message"></div>
</form>
<!-- END contact form -->
</main>
<!-- END main content -->
<!-- footer -->
<footer>
<p>©2019 placeholder</p>
</footer><!-- END footer-->
</div><!-- END holder -->
<!-- JavaScript and jQuery -->
<script src="https://code.jquery.com/jquery-3.4.0.min.js" integrity="sha256-BJeo0qm959uMBGb65z40ejJYGSgR7REI4+CW1fNKwOg=" crossorigin="anonymous"></script>
<script src="js/mainjs.js"></script>
</body>
</html>
This is the PHP (saved in the same directory as kontakt.php):
<?php
$titles = $usrmsg = $usrname = $email = "";
$errors = array("email"=>"", "usrname"=>"", "usrmsg"=>"", "titles"=>"");
if(isset($_POST["submit"])){
//check Email
if(empty($_POST["email"])){
$errors["email"] = "Bitte Email Adresse angeben.";
} else {
$email = $_POST["email"];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errors["email"] = "Die Email Adresse sollte gültig sein.";
}
}
//check name
if(empty($_POST["usrname"])){
$errors["usrname"] = "Wie heißt du?";
} else {
$usrname = $_POST["usrname"];
$usrname = filter_var($usrname, FILTER_SANITIZE_STRING);
if(!preg_match("/^[a-zA-Z\s]+$/", $usrname)){
$errors["usrname"] = "Sorry! Der Name darf nur Buchstaben und Leerzeichen enthalten.";
}
}
//check message
if(empty($_POST["usrmsg"])){
$errors["usrmsg"] = "Hier sollte etwas Text stehen. Muss ja nicht viel sein.";
} else {
$usrmsg = $_POST["usrmsg"];
$usrmsg = filter_var($usrmsg, FILTER_SANITIZE_STRING);
}
//check titles
$titles = $_POST["titles"];
if ($titles==NULL) {
$errors["titles"] = "Welche Ansprache darf ich verwenden?";
}
}
?>
EDIT: Here's the JS for client-side form validation (it's not a finished version, some validations are still missing/may get changed, but so far it's working as it should):
var myForm = document.forms.myForm;
var message = document.getElementById('message');
myForm.onsubmit = function() {
//get IDs for the title
var mr = document.getElementById('mr');
var mrs = document.getElementById('mrs');
var mx = document.getElementById('mx');
var pers = document.getElementById('person');
//get ID for the textarea
var usrInput = document.getElementById('message-me');
if (myForm.usrname.value == "") {
message.innerHTML = "Moment! Wie heißt du?"
return false;
} else if (usrInput.value == "") {
message.innerHTML = "Das Nachrichtenfeld sollte nicht leer sein..."
return false;
} else if (email.value == "") {
message.innerHTML = "Wie lautet deine Email Adresse?"
return false;
} else if (usrInput.value.length < 10) {
//check min length of textarea
message.innerHTML = "Die Nachricht sollte etwas länger sein..."
return false;
} else if (!mr.checked &&
!mrs.checked &&
!mx.checked &&
!pers.checked) {
message.innerHTML = "Welche Ansprache darf ich verwenden?"
return false;
} else {
message.innerHTML = "";
return true;
}
I'm using XAMPP (Apache) to test this via localhost.
How can I get the form to send POST, not GET? Did I overlook syntax errors, typos or are there errors with my variables that I can't find? Thx for any input.
This happens sometimes. I don't think I am experienced enough to give you a perfect solution but here's a bunch of try outs you can implement:
Try to write the "post" keyword in capitals (like "POST").
Sometimes the xampp server does not reflect changes even after you save and refresh. Try refreshing with (ctrl+F5). This imposes a hard refresh causing the xampp server to reload all the resourses.
Try restarting the xampp server.
Please revert if anything was helpful....
I Try to made a - as I thinked - easy Script, which simply checks the MX Record of a Mail address and if it Matches, redirect to an specific URL.
Suddenly... I have no clue how to work it out. I found some things on google, but it seems not to work. Where is my Fault?
<title>Mailredirector</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- ********** HEADER START ********** -->
<hr>
<br>
<!-- ********** HEADER ENDE ********** -->
<!-- ********** FORMULAR START ********** -->
<form method="post" action="mxnew.php">
<p style="text-align: center">
Bitte geben sie Ihre Mailadresse ein und klicken sie auf Senden<br>
<br>
<br>
<b>Email: </b><input type="email" name="email" id="email" style="height: 30px; width: 350px;"/>
<br>
<input type="submit" value="Check" id="dsubmit" name ="submit" style="width: 80px; height: 30px;"/>
</p>
</form>
<!-- ********** FORMULAR ENDE ********** -->
<!-- ********** FOOTER START ********** -->
<hr>
<!-- ********** FOOTER ENDE ********** -->
</body>
</html>
<?php
if (isset($_POST['submit'])) {
$email = $_POST['email'];
/* <----- Domain von Name trennen ----->*/
$domain = substr(strrchr($email, "#"), 1);
/* <----- MX Record und Domain prüfen ----->*/
function mxrecordValidate($email, $domain) {
$arr = dns_get_record($domain, DNS_MX);
if ($arr[0]['host'] == $domain && !empty($arr[0]['target'])) {
return $arr[0]['target'];
}
/* <----- Weiterleitungen an andere Domain ----->*/
if ($arr['target'] == mx.domain.com) {
Header ('location: http://google.ch');
die();
}
if ($arr['target'] == all01.mx.domain.ch) {
Header ('location: http://google.fr');
die();
}
else {
Header ('location: http://google.com');
die();
}
}
}
?>
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\">
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.