You can use curl() to access the script in the background
<?php
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://domain.com/script.php?s=email&m=message");
curl_exec ($curl);
curl_close ($curl);
script.php
<?php
// send an email confirming script.php was accessed (with params)
$subject = strip_tags($_GET['s']);
$message = strip_tags($_GET['m']);
mail('email@email.com',$subject,$message);
http://us2.php.net/curl
You can also do this asynchronously via ajax on document load
I'm not a javascript guy, so somebody may chime in with an issue doing it via ajax, however it's working for me in testing...
<script src="//code.jquery.com/jquery.js"></script>
<script>
$(document).ready(function() {
$.ajax({
type: 'POST',
url: 'script.php',
data: 's=subject&m=message',
cache: false,
success: function(data){
// put success stuff here
alert(data); // for testing
}
});
return false;
});
</script>
script.php
<?php
if($_SERVER['REQUEST_TYPE'] == 'POST') {
$subject = strip_tags(trim($_POST['s']));
$message = strip_tags(trim($_POST['m']));
if(mail('email@email.com',$subject,$message)) {
echo 'true';
} else {
echo 'false';
}
}
Edit: updated answer per OP's question in comments.
Edit: added ajax example