[ create a new paste ] login | about

Link: http://codepad.org/VlGCP10f    [ raw code | fork ]

PHP, pasted on Apr 2:
<?php
if($_POST)
{
	$to_Email   	= "myemail@gmail.com"; //Replace with recipient email address
	$subject        = '7L Studio - newsletter subscriber'; //Subject line for emails
	
	
	//check if its an ajax request, exit if not
    if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
	
		//exit script outputting json data
		$output = json_encode(
		array(
			'type'=>'error', 
			'text' => 'Request must come from Ajax'
		));
		
		die($output);
    } 
	
	//check $_POST vars are set, exit if any missing
	if(!isset($_POST["userEmail"]) )
	{
		$output = json_encode(array('type'=>'error', 'text' => 'The field is empty!'));
		die($output);
	}

	//Sanitize input data using PHP filter_var().
	$user_Email       = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
				
							  'E-mail: ' . $user_Email . ;
	
	//additional php validation
	if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
	{
		$output = json_encode(array('type'=>'error', 'text' => 'Prosím zadejte platný email!'));
		die($output);
	}
		
	//proceed with PHP email.
	$headers = 'From: '.$user_Email.'' . "\r\n" .
	'Reply-To: '.$user_Email.'' . "\r\n" .
	'X-Mailer: PHP/' . phpversion();
	
	$sentMail = @mail($to_Email, $subject, $headers);
	
	if(!$sentMail)
	{
		$output = json_encode(array('type'=>'error', 'text' => 'Došlo k chybě v odesílání emailu, prosím kontaktujte administratora.'));
		die($output);
	}else{
		$output = json_encode(array('type'=>'message', 'text' => 'Byl jste přihlášen k našemu newsletteru, děkujeme.'));
		die($output);
	}
}
?>


Create a new paste based on this one


Comments: