<?
// ------------------------------------------------------------------------- //
// Certains hébergeurs ne proposent pas la fonction 'mail' pour l'envoi de //
// messages. Il est possible de combler cette absence en utilisant un script //
// placé chez un autre hébergeur autorisant cette fonction. //
// ------------------------------------------------------------------------- //
// Auteur: Tristan Marly //
// Email: tmarly@free.fr //
// ------------------------------------------------------------------------- //
// Il y a au total 3 scripts :
// ---------------------------
// - 'mailer.php3' est à mettre sur le site proposant la fonction mail.
// - 'sendmail.php3' est à mettre sur le site qui veur émettre des mails mais
// qui n'a pas la fonction. Il faut configurer les parametres cités au début
// du script.
// - 'test.php3' permet de tester l'envoi de mail.
// ------------------------------------------------------------------------- //
// sendmail.php3 //
// ------------------------------------------------------------------------- //
// This script is on the account which does not allow the 'mail' function. //
// ------------------------------------------------------------------------- //
// Remote Parameters. You must set these variables correctly. //
// $mailHost Host of the remote script (i.e. "my.domain.com"). Must not end //
// with '/'. //
// $mailScript Path of the remote script (i.e "dir/myscipt.php3"). Must not //
// start with '/'. //
// $mailPassword A password in order to make sure no little freak do any //
// spamming using your account. This password must be the same than the one //
// in the remote script. //
// ------------------------------------------------------------------------- //
$mailHost = "remote.domain.com";
$mailScript = "scripts/mailer.php3";
$mailPassword = "aFziHkzeOBZkzer548rz";
// ------------------------------------------------------------------------- //
// Send a mail using a script located on a remote server. return true if the //
// mail has been sent. If the returned value is false, $errorMessage contain //
// some comments about the failure. $to, $subject, $message and $header are //
// the same parameters than the PHP 'mail' function. If you want to specify //
// the sender, place "From: my@mail.com" in $header. //
// ------------------------------------------------------------------------- //
function sendmail($to, $subject, $message, $header = false) {
global $errorMessage, $mailHost, $mailScript, $mailPassword;
// Let's make sure parameters are correct.
if (!$to || !$subject || !$message) {
$errorMessage = "You did not give all the needed parameters.\n";
return false;
}
// Let's encode data.
$data = "to=" . urlencode($to);
$data .= "&subject=" . urlencode($subject);
$data .= "&message=" . urlencode($message);
$data .= "&pass=" . urlencode($mailPassword);
if ($header) $data .= "&header=" . urlencode($header);
// Let's build the post request.
$message = "POST /$mailScript HTTP/1.1\r\n";
$message .= "Host: $mailHost\r\n";
$message .= "Content-type: application/x-www-form-urlencoded\r\n";
$message .= "Content-length: ".strlen($data)."\r\n";
$message .= "\r\n";
$message .= "$data\r\n";
// Let's connect.
$stream = fsockopen( $mailHost, 80, &$errno, &$errorMessage, 20);
if ($stream && fputs($stream,$message)) {
while($l = fgets($stream,4096));
fclose($stream);
return true;
}
return false;
}
// ------------------------------------------------------------------------- //
// mailer.php3 //
// ------------------------------------------------------------------------- //
// This script must be on an account allowing the 'mail' function. //
// ------------------------------------------------------------------------- //
// This password must be the same than the one in sendmail.php3.
$password = "aFziHkzeOBZkzer548rz";
// If you are on Nexen, uncomment the following line.
// include("mail.inc");
// Let's make some kind of authentification ...
if ($pass == $password) {
// All the fields are correct ?
if (isset($to) && isset($subject) && isset($message)) {
if (isset($header)) {
// If you are on Nexen, replace 'mail' with 'email'.
mail($to, $subject, $message, $header);
} else {
// If you are on Nexen, replace 'mail' with 'email'.
mail($to, $subject, $message);
}
}
}
// ------------------------------------------------------------------------- //
// test.php3 //
// ------------------------------------------------------------------------- //
include("sendmail.php3");
if (sendmail("me@domain.fr", "Test", "It works !", "From: me@mail.com")) {
print("Mail sent !");
} else {
print("An error occured: $errorMessage");
}
?>