Hi,
I like to use my own simple subscription writing emails into a text-file -- but just got an ’irrational’ problem with ModX.
The Chunk {{subscribe}} implemented in the website:
<!-- checks input before submitting -->
<script language="JavaScript">
var find_result;
function form_email(){
var str=document.validation.email.value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
find_result=true;
else{
alert("Bitte geben Sie eine gültige Email-Adresse an!")
find_result=false;
}
return (find_result);
}
function checkbae(){
if (document.layers||document.getElementById||document.all)
return form_email();
else
return true;
}
</script>
<!-- the field where the user enters the email -->
<center>
<form name="validation" action="index.php?id=100" onSubmit="return checkbae()" method="post">
<p>Inform me if a new version is released:</p>
<p>Email: <input type="text" name="email" style="width:120px;" /></p>
<input id="submitButton" type="image" src="assets/images/button.png" alt="Register" class="subbutton" />
</form>
</center>
The referring document (see form: action=index.php?id=100) has the snippet "[[subscriber]]" included:
The Snippet:
<?php
// transferred EMAIL
$email = $_POST['email'];
// IP FUNCTION
function getIp(){
if( isset( $_SERVER ['HTTP_X_FORWARDED_FOR'] ) ){
$ip = $_SERVER ['HTTP_X_FORWARDED_FOR'];
}elseif( isset( $_SERVER ['HTTP_VIA'] ) ){
$ip = $_SERVER ['HTTP_VIA'];
}elseif( isset( $_SERVER ['REMOTE_ADDR'] ) ){
$ip = $_SERVER ['REMOTE_ADDR'];
}else{
$ip = "Anonima" ;
}
return $ip;
}
$ipadresse = getIp();
// DATE formatting
$heute = getdate();
if($heute[mon]<10) { $monat = "0".$heute[mon]; }
else { $monat = $heute[mon]; }
if($heute[mday]<10) { $tag = "0".$heute[mday]; }
else { $tag = $heute[mday]; }
if($heute[minutes]<10) { $minute = "0".$heute[minutes]; }
else { $minute = $heute[minutes]; }
// WRITE FILE
$fileURL = (string) ($modx->config['base_path'].'assets/subscribers.txt');
$file = fopen($fileURL, 'a');
// alternatively I tried: $file = fopen("assets/subscribers.txt", 'a');
$writeThat = $email.";".$heute[year]."-".$monat."-".$tag." ".$heute[hours].":".$minute." - IP: ".$ipadresse."\n";
fwrite($file, $writeThat);
fclose($file);
// inform me via email
$mail_to = '[email protected]';
$subject = 'New Subscriber';
$text = $heute[year]."-".$monat."-".$tag." ".$heute[hours].":".$minute." - IP: ".$ipadresse."\n".$email."\n";
$header = "From: [email protected]";
mail($mail_to, $subject, $text, $header);
?>
When I tried it first everything worked fine. Some days passed, then I got no new subscribers so I tried the subscription myself again... and nothing happened! Changing the code again, clearing the cache, trying it once more... it worked again. Days later, the same: doesn’t work...
Please help me. What am I doing wrong? Has the behaviour something to do with the cache? Can’t I use php this way in modx? (I am no php-developer, sorry.)