allow only one or some email extension - php

I just want to ask how can i allow #abc.co.uk or #def.com.tr or something else email extenssions. when user register my website ?
Like if user try to register with (name#hotmail.com) then this email is not allowing. But if user try to register with (name#abc.co.uk or #def.com.tr) then user can register the website.
$("#email").change(function()
{
var email = $("#email").val();
var msgbox = $("#estatus");
if(email.length >= 3)
{
$("#estatus").html('<div class="checking">Checking availability...</div>');
$.ajax({
type: "POST",
url: "check_mail.php",
data: "email="+ email,
success: function(msg){
$("#estatus").ajaxComplete(function(event, request, settings){
var d = msg;
var str=msg.substr(0, 2);
$("#estatus").html('');
if(str == 'OK')
{
$("#email").removeClass("no");
$("#email").addClass("yes");
//msgbox.html('<font color="Green"> Ok </font> ');
}
else
{
$("#email").removeClass("yes");
$("#email").addClass("no");
msgbox.html(msg);
}
});
}
});
}
else
{
$("#email").addClass("no");
$("#estatus").html('<div class="error">Enter a valid e-mail</div>');
}
return false;
});
PHP check_mail.php
<?php
error_reporting(0);
include_once 'includes/db.php';
include_once 'includes/Sc_Script.php';
$Sc = new Check_Email();
if(isSet($_POST['email'])){
$value=$_POST['email'];
// Check the mail is already in using or not
$check=$Sc->Login_Check($value,0);
if($check) {
echo '<div class="error">'.$value.' = This email address is already in use.</div>';
} else {
// Else continue
echo 'OK';
}
}
?>

First you need to pull out the domain and then you need to check that it is contained within some whitelist array:
function isDomainAllowed($email_address)
{
$domain = substr($email_address, strrpos($email_address, '#') + 1);
if (in_array(strtolower($domain), array(
'abc.co.uk',
'def.com.tr',
)))
{
return TRUE;
}
return FALSE;
}
if (isDomainAllowed($email_address))
{
// Allowed
}
else
{
// Not allowed
}

You have check each & every whitelist domain with the supplied email.
$emailList = array();
$emailList = ["abc.in","def.uk"];
$flag = false;
foreach($emailList as $email)
{
if(stripos($_POST['email'],$email) != false)
$flag = true;
}
if($flag == false)
echo "Invalid email domain";

Related

Stop Execution Php

I have this code , iam trying to use javascript to stop executing but its not working with javascript , any suggestions ? Am just trying to stop executing if the return was false from the javascript
if(mysql_num_rows($runzz)==0){
echo "<p align='center'><font size='5'>This Item $code1 - $code2 - ".$rw2['description']. "</br></br> Doesn't Exist In The <u><b>".$rowto['name']."</b></u></br></br> Wanna Add IT ?</font></p>";
?>
<script>
function check(){
var r = confirm("Press a button!");
if (r == true) {
return true;
} else {
return false;
}
}
check();
</script>
<?php
}
$insert="INSERT INTO transfercopy(warehouseidfrom,warehouseidto,qty,itemid,uid)VALUES('$from','$to','$qty','$codeid','$uid')";
$run=mysql_query($insert,$con);
if(!$run)die("error".mysql_error());
I am adding sample code to give you an idea, how you could use AJAX Call with it.
<?php
if(mysql_num_rows($runzz)==0){
echo "<p align='center'><font size='5'>This Item $code1 - $code2 - ".$rw2['description']. "</br></br> Doesn't Exist In The <u><b>".$rowto['name']."</b></u></br></br> Wanna Add IT ?</font></p>";
?>
<script>
function check(){
var r = confirm("Press a button!");
if(r) {
// Add additional parameter
// You could use POST method too. Use whatever make sense to you.
var urlLink = 'http://www.example.com/warehouse/record.php?from=<?php echo $from?>&to=<?php echo $to?>';
$.ajax({
type: 'GET',
url: urlLink,
success: function(data) {
if(data == 'success') {
return 'You have successfully added new record!';
}
},
error: function(data) {
console.log(data);
}
});
} else {
return false;
}
}
check();
</script>
<?php } ?>
<?php
// -- New File: record.php File
//
// You might wanna add the check, that it's the legit request and all the PHP Validation
$form = $_GET['from'];
$to = $_GET['to'];
$qty = $_GET['qty'];
$codeid = $_GET['codeid'];
$uid = $_GET['uid'];
$insert="INSERT INTO transfercopy(warehouseidfrom,warehouseidto,qty,itemid,uid)VALUES('$from','$to','$qty','$codeid','$uid')";
$run=mysql_query($insert,$con);
if(!$run) die("error".mysql_error());
else return 'success';
?>

Couldn't get response from database with jQuery using PHP post request

I cannot get this script work. I try to warn if login that user entered is available. But I cannot manage this script to work:
$( "#myRegForm" ).submit(function( event ) {
var errors = false;
var userAvi = true;
var loginInput = $('#login').val();
if( loginInput == ""){
$("#errorArea").text('LOGIN CANNOT BE EMPTY!');
$("#errorArea").fadeOut('15000', function() { });
$("#errorArea").fadeIn('15000', function() { });
errors = true;
}
else if(loginInput.length < 5 ){
$("#errorArea").text('LOGIN MUST BE AT LEAST 5 CHARACTERS!');
$("#errorArea").fadeOut('15000', function() { });
$("#errorArea").fadeIn('15000', function() { });
errors = true;
}
else if (loginInput.length >=5) {
$.post('checkLogin.php', {login2: loginInput}, function(result) {
if(result == "0") {
alert("this");
}
else {
alert("that");
}
});
}
if (errors==true) {
return false;
}
});
Everything works fine until loginInput.length >=5 else block. So I assume there is a problem with getting answer from PHP file, but I cannot handle it, though I tried many different ways. Here is checkLogin.php's file (note that jQuery script and PHP file are in the same folder):
<?php
include ("bd.php");
$login2 = mysql_real_escape_string($_POST['login2']);
$result = mysql_query("SELECT login FROM users WHERE login='$login2'");
if(mysql_num_rows($result)>0){
//and we send 0 to the ajax request
echo 0;
}
else{
//else if it's not bigger then 0, then it's available '
//and we send 1 to the ajax request
echo 1;
}
?>
<?php
include ("bd.php");
$login2 = mysql_real_escape_string($_POST['login2']);
$result = mysql_query("SELECT login FROM users WHERE login='$login2'");
if(mysql_num_rows($result)>0){
//and we send 0 to the ajax request
echo "0"; // for you to use if(if(result == "0") you should send a string
} else {
//else if it's not bigger then 0, then it's available '
//and we send 1 to the ajax request
echo "1";
}
?>
You're literally sending the string 'loginInput'.
change
$.post('checkLogin.php', {login2: 'loginInput'}, function(result) {
to
$.post('checkLogin.php', {login2: loginInput}, function(result) {
Edit
I would just comment out everything except the following for now and see if that at least works
$.post('checkLogin.php', {login2: 'loginInput'}, function(result) { // put loginInput back in quotes
alert('#'+result+'#'); // # to check for whitespace
});

Validation for email availability if email exists with an alert using php [duplicate email]

I wrote some ajax validation for email check by verifying the availability using php the ajax script just displays whether email is available or not?
<script type="text/javascript">
$(document).ready(function()
{
$("#email_id").change(function(){
var email = $("#email_id").val();
var regdata = /^([A-Za-z0-9_\-\.])+\#([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(!(regdata).test($("#email_id").val()))
{
$("#email_id").css('border','1px solid red');
$("#email_id").focus();
$("#status").html("enter the valid emailid!");
return false;
}
else{
$("#email").css('border','1px solid #7F9DB9');
$("#email_id").html('Checking Email Availability...');
$.ajax({
type: "POST",
url: "fresherreg_email_avail.php",
data:"q="+ email,
success: function(server_response){
$("#status").ajaxComplete(function(event,request){
if(server_response == '0')
{
$("#status").html('Email Available');
}
else if(server_response == '1')
{
$("#status").html('Email Not Available');
}
});
}
});
}
});
});
</script>
and my php availability check code is
<?php
include_once("include_dao.php");
$q = $_REQUEST['q'];
if($q != "")
{
$row=DAOFactory::getTblFreshersRegistrationDAO()->queryByEmailId($q);
$num = count($row);
if($num > 0)
{
echo "1";
}
else
{
echo "0";
}
}
else
{
echo "Email Id should not be empty";
}
?>
what i need is?
it should show an alert using script until he choose a new mail id
It can be done this way . I will edit your code and add the required thing .
In the javascript/jquery part:
<script type="text/javascript">
$(document).ready(function()
{
$("#email_id").change(function(){
var email = $("#email_id").val();
var regdata = /^([A-Za-z0-9_\-\.])+\#([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(!(regdata).test($("#email_id").val()))
{
$("#email_id").css('border','1px solid red');
$("#email_id").focus();
$("#status").html("enter the valid emailid!");
return false;
}
else{
$("#email").css('border','1px solid #7F9DB9');
$("#email_id").html('Checking Email Availability...');
$.ajax({
type: "POST",
url: "fresherreg_email_avail.php",
data:"q="+ email,
success: function(server_response){
if(server_response == '0')
{
$("#status").append("<font color='green'>email available</font>");
}
else if(server_response == '1')
{
$("#status").append("<font color='red'>email already exits</font>");
}
else
{
$("#status").append("<font color='red'>"+server_response+"</font>");
}
}
});
}
});
});
</script>
Now in your php script .
<?php
include_once("include_dao.php");
$q = $_REQUEST['q'];
if($q != "")
{
$row=DAOFactory::getTblFreshersRegistrationDAO()->queryByEmailId($q);
$num = count($row);
if($num > 0)
{
echo "1";
}
else
{
echo "0";
}
}
else
{
echo "Email Id should not be empty";
}
?>
<script type="text/javascript">
$(document).ready(function(){
$('#submit');
var emaildone = false;
var myRegForm = $("#registration"),email = $("#email_id"), status = $("#status");
myRegForm.submit(function(){
if(!emaildone)
{
alert("Email Id Already Exists!!! So Please Try Another Email Id");
email.attr("value","");
email.focus();
return false;
}
});
email.blur(function(){
$.ajax({
type: "POST",
data: "q="+$(this).attr("value"),
url: "fresherreg_email_avail.php",
beforeSend: function(){
status.html('<img src="images/loader.gif" align="absmiddle"><font color="blue">Checking Email Availability...</font>');
},
success: function(data){
if(data == "invalid")
{
emaildone = false;
status.html("<font color='red'>Inavlid Email!! Please Select a Vaild Email</font>");
}
else if(data != "0")
{
emaildone = false;
status.html('<img src="images/not_available.png" align="absmiddle"><font color="red">Email Already Exist</font>');
}
else
{
emaildone = true;
status.html('<img src="images/available.png" align="absmiddle"> <font color="green">Email Available</font>');
}
}
});
});
});
</script>
Change script to this.

ModalBox Email pass php variable to sms sender

Ok, so I use ModalBox to create an email form on my website..however, i need the modal box to send the email not to me, but to the user who added the car(its a car selling website), and so I need to pass the $email variable to the sendmessage.php.
This is what i did so far:
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
setTimeout("$.fancybox.close()", 10);
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>Se trimite...</em>");
$.ajax({
type: 'POST',
url: 'http://automoka.ro/sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Mesajul a fost trimis!</strong></p>");
setTimeout("$.fancybox.close()", 10);
$_POST['contact'] = $email;
});
}
}
});
}
});
});
and in the php sender :
$email = $_POST['contact'];
$sendto = $email;
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
if(#mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
What am I doing wrong? Please help....Thanks in advance!
EDIT:
Nevermind..figured it out!...I added another textarea which was hidden to the modalbox...and used post to get it to sendmessage.php.

AJAX with HTML?

I have a email system I am building for a company that they want to send emails with it. I have a custom HTML editor for it. What I am wanting to do it post the contents to a external PHP file and have it add to the database.
function schedule_eblast (html) {
var answer = confirm("Are you sure you want to start sending this E-blast?");
if (answer) {
$.ajax({
type: "POST",
url: "./../../../processes/eblast_schedule.php",
data: {'html_text': html},
success: function(theRetrievedData) {
if (theRetrievedData == "done") {
alert("Your eblast has been successfully scheduled to send. To check it's status, go to the manage eblasts page.");
} else {
alert(theRetrievedData);
}
}
});
return false;
}
And here is what I have for the header in the eblast_schedule.php file:
<?php
include('connect.php');
if ((isset($_POST['html_text'])) && (strlen(trim($_POST['html_text'])) > 0)) {
$html_text = stripslashes(strip_tags($_POST['html_text']));
} else {
$html_text = "";
}
if ((isset($_POST['subject'])) && (strlen(trim($_POST['subject'])) > 0)) {
$subject = stripslashes(strip_tags($_POST['subject']));
} else {
$subject = "";
}
ob_start();
And yes, it does get called. But when outputting html_text, it removes all the HTML. And when adding to the database, it doesn't show the HTML either.
Help! Thanks.
Remove those functions and add mysql_real_escape_string and it should work fine...
include('connect.php');
if ((isset($_POST['html_text'])) && (strlen(trim($_POST['html_text'])) > 0)) {
$html_text = mysql_real_escape_string($_POST['html_text']);
} else {
$html_text = "";
}
if ((isset($_POST['subject'])) && (strlen(trim($_POST['subject'])) > 0)) {
$subject = mysql_real_escape_string($_POST['subject']);
} else {
$subject = "";
}
ob_start();

Categories