this file takes out a list of emails from an external .txt, and allow me to send messages to these emails.
the code is as follows:
Code: Select all
<center>
<?
// Some variables;
// Your emails list file;
$filelist = "testo.txt" ;
// Email headers that subscribed users see
// when you send them an email;
$adminmail = "nome@email.com" ;
$emailheaders = "From: " . $adminmail . "\nReply-To: " . $adminmail ;
// By default we display entries;
if (!isset( $mode ))
$mode = "unknown" ;
// Since all administration is in one file,
// we choose what to to do now;
switch ( $mode ) {
case "create" : createList (); break;
case "display" : displayEntries ( $filelist ); break;
case "add" : addEntry ( $email ); break;
case "edit" : displayEditForm ( $id ); break;
case "doEdit" : editEntry ( $email , $oldvalue ); break;
case "delete" : deleteEntry ( $id ); break;
case "send" : sendNews ( $subject , $message ); break;
default:
if ( file_exists ( $filelist )) {
displayEntries (); displayAddEntryForm ();
}
}
/* THIS IS THE PART WHERE WE CREATE A MAILING LIST FILE AUTOMATICALLY */
/* IGNORE IT IF YOU HAVE CREATED IT MANUALLY (NOTHING WILL BE DISPLAYED */
if (! file_exists ( $filelist )) {
echo "<h2>Please, make sure you have 777 permissions for current
directory to create the mailing list file and click the button or
create it manually and set 666 permissions on it</h2>" ;
echo "<form name=createFile action=adminemail.php method=post>" ;
echo "<input type=submit name=mode value=create mailing list file>" ;
echo "</form>" ;
exit;
}
function createList () {
$fp = fopen ( $GLOBALS [ "filelist" ], "w" );
if ( $fp ) {
echo "<h2>Mailing list created!</h2>" ;
echo "<b>" . $GLOBALS [ "filelist" ] . "</b>" ;
echo "<meta http-equiv='Refresh' content='1; URL=adminemail.php'>" ;
exit;
}
else
echo "Error!" ;
}
/**************************************************************************/
// Sends news to subscribers;
function sendNews ( $subject , $message ) {
$filecontents = file ( $GLOBALS [ "filelist" ]);
for ( $i = 0 ; $i < sizeof ( $filecontents ); $i ++) {
$a = mail ( $filecontents [ $i ], $subject , stripslashes ( $message ), $GLOBALS [ "emailheaders" ]);
if (! $a )
exit;
}
echo "Spam sent! <img src=" images / smilies / blink . gif " border=" 0 " alt="">" ;
echo "<meta http-equiv='Refresh' content='1; URL=adminemail.php'>" ;
exit;
}
// Displays the form to add emails to list;
function displayAddEntryForm () {
echo "<h1>Add email to the mailing list:</h1>" ;
echo "<form name=addEntry action=adminemail.php method=get>" ;
echo "<input type=text name=email>" ;
echo "<input type=hidden name=mode value=add>" ;
echo "<input type=submit name=submit value=add>" ;
echo "</form>" ;
}
// Adds emails to list;
function addEntry ( $email ) {
$fp = fopen ( $GLOBALS [ "filelist" ], "a" );
$emailsize = strlen ( $email . "\n" );
$fw = fwrite ( $fp , $email . "\n" , $emailsize );
if ( $fw ) {
echo "<h2><div align=center>Email added!</div></h2>" ;
echo "<meta http-equiv='Refresh' content='1; URL=adminemail.php'>" ;
exit;
}
else
echo "Error!" ;
}
// Displays emails from list;
// by default it display last 10 emails;
function displayEntries () {
echo "Show last: <a href=adminemail.php?limit=10>10 emails</a> ||
<a href=adminemail.php?limit=20>20 emails</a> ||
<a href=adminemail.php?limit=50>50 emails</a> ||
<a href=adminemail.php?showall=>Show all</a><p> " ;
$filecontents = file ( $GLOBALS [ "filelist" ]);
if (isset( $GLOBALS [ "limit" ]))
$limit = $GLOBALS [ "limit" ];
if ((!isset( $GLOBALS [ "limit" ])) and (!isset( $GLOBALS [ "showall" ])))
$limit = 10 ;
if (isset( $GLOBALS [ "showall" ])) {
for ( $i = sizeof ( $filecontents )- 1 ; $i >= 0 ; $i --) {
echo $filecontents [ $i ] . " <a href=adminemail.php?mode=edit&id=" .
$filecontents [ $i ] . ">Edit</a> || <a href=adminemail.php?mode=delete&id=" .
$filecontents [ $i ] . ">Delete</a><br>" ;
}
}
elseif (isset( $limit )) {
$count = 1 ;
for ( $i = sizeof ( $filecontents )- 1 ; $count <= $limit ; $i --) {
echo $filecontents [ $i ] . " <a href=adminemail.php?mode=edit&id=" .
$filecontents [ $i ] . ">Edit</a> || <a href=adminemail.php?mode=delete&id=" .
$filecontents [ $i ] . ">Delete</a><br>" ;
$count ++;
}
}
}
// Displays the form to edit an email;
function displayEditForm ( $id ) {
echo "<h1>Edit Email:</h1>" ;
echo "<form name=editForm action=adminemail.php method=get>" ;
echo "<input type=text name=email value=" . $id . ">" ;
echo "<input type=hidden name=oldvalue value=" . $id . ">" ;
echo "<input type=hidden name=mode value=doEdit>" ;
echo "<input type=submit name=submit value=update>" ;
echo "</form>" ;
exit;
}
// Edits an email and writes the updated file;
function editEntry ( $email , $oldvalue ) {
$filecontents = file ( $GLOBALS [ "filelist" ]);
for ( $i = 0 ; $i < sizeof ( $filecontents ); $i ++) {
if ( chop ( $filecontents [ $i ]) == $oldvalue ) {
$filecontents [ $i ] = $email . "\n" ;
$fp = fopen ( $GLOBALS [ "filelist" ], "w+" );
for ( $a = 0 ; $a < sizeof ( $filecontents ); $a ++) {
$emailsize = strlen ( $filecontents [ $a ] . "\n" );
$fw = fwrite ( $fp , $filecontents [ $a ], $emailsize );
}
echo "<h2><div align=center>Modified!</div></h2>" ;
echo "<meta http-equiv='Refresh' content='1; URL=adminemail.php'>" ;
exit;
}
}
}
// Deletes an email and writes an updated file;
function deleteEntry ( $id ) {
$filecontents = file ( $GLOBALS [ "filelist" ]);
for ( $i = 0 ; $i < sizeof ( $filecontents ); $i ++) {
if ( chop ( $filecontents [ $i ]) == $id ) {
$filecontents [ $i ] = "" ;
$fp = fopen ( $GLOBALS [ "filelist" ], "w+" );
for ( $a = 0 ; $a < sizeof ( $filecontents ); $a ++) {
$emailsize = strlen ( $filecontents [ $a ]);
$fw = fwrite ( $fp , $filecontents [ $a ], $emailsize );
}
echo "<h2><div align=center>Deleted!</div></h2>" ;
echo "<meta http-equiv='Refresh' content='1; URL=adminemail.php'>" ;
exit;
}
}
}
?>
<h2>Insert here text to send out:</h2>
<form name=sendEmail action=adminemail.php method=post>
Subject:<br><input type=text name=subject><br>
Message:<br><textarea name=message rows=10 cols=50></textarea><br>
<input type=submit name=mode value=send>
</form>
<a href="./index.html"><h2>Back to home</h2></a>
</center>
Instead the same script in another domain (altervista.org) works perfectly. So I thought it was a permissions problem, but I noticed that writing files is enabled because:
Code: Select all
<?php
$stringa = $_POST [ 'email' ]. "\n" ;
// Scrittura del file
$scrivi_file = fopen ( "testo.txt" , "a+" );
fputs ( $scrivi_file , $stringa );
fclose ( $scrivi_file );
?> I can not understand what it can be. Help me please!
Thanks a lot and sorry for my bad english.