Created
February 25, 2012 02:03
-
-
Save OscarGodson/1905250 to your computer and use it in GitHub Desktop.
Send mail via JS and JSONP with some shitty PHP code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JS Bin</title> | |
<style> | |
</style> | |
</head> | |
<body> | |
<p id="sending">Sending mail...</p> | |
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/javascript; charset=utf8'); | |
if(!isset($_GET['callback'])){ | |
$callback = 'callback'; | |
} | |
else{ | |
$callback = $_GET['callback']; | |
} | |
if(!isset($_GET['to'])){ | |
$to = '[email protected]'; | |
} | |
else{ | |
$to = $_GET['to']; | |
} | |
if(!isset($_GET['from'])){ | |
$from = '[email protected]'; | |
} | |
else{ | |
$from = $_GET['from']; | |
} | |
if(!isset($_GET['subject'])){ | |
$subject = ''; | |
} | |
else{ | |
$subject = $_GET['subject']; | |
} | |
if(!isset($_GET['message'])){ | |
$message = ''; | |
} | |
else{ | |
$message = $_GET['message']; | |
} | |
echo $callback.'({status:'.mail($to, $subject, $message, 'From: '.$from).'});'; | |
//I'm sure there is a better way of doing this, but it works. | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var emailData = { | |
to:'[email protected]', | |
from:'[email protected]', | |
subject:'Just a test', | |
message:'It worked!' | |
} | |
$.getJSON('http://kneedeepincode.com/sendmailjs?callback=?',emailData,function(data){ | |
var result = 'ERROR'; | |
if(data.status == 1){ | |
result = 'Mail sent successfully, yo!'; | |
} | |
$('#sending').text(result); | |
}); | |
//Demo: http://jsbin.com/awakoj/edit#javascript,html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment