To jest plik index.php
Dodać to tu gdzieś po prostu?
Kod
<?
require('config.inc.php');
require('functions.inc.php');
// Max execution time of script. This does not include sleep time, so only restricts time
// allowed for mailing.
set_time_limit(3600);
$type = $_GET['type'];
$addr = stripslashes(urldecode($_GET['email']));
if ($type == 'sub') {
// subscribe address. Actually, all it does is send the confirmation email
if (!preg_match('#^([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+[^\".,?! ])$#i', $addr)) {
$err = 'Your email address appears to be invalid.';
}
if (!isset($err)) {
$f = openfile($cfg['listfile']);
$exists = false;
while ($item = readitem($f)) {
if ($item['addr'] == $addr) {$exists = true;break;}
}
if ($exists) {
$err = 'That address is already subscribed to the list.';
}
}
if (!isset($err)) {
// send confirmation email
$headers = 'From: '.$cfg['from'];
if ($cfg['headers']) {
foreach ($cfg['headers'] as $val) $headers .= "\n".$val;
}
$headers .= "\n".$cfg['header_plain'];
if (!@mail($addr, $cfg['subj_conf'], sprintf($cfg['msg_conf'], '?type=confirm&email='.urlencode($addr)), $headers)) {
$err = 'There was an error sending the confirmation email. Please try again later.';
}
}
if (!isset($err)) {
// confirmation sent
if (isset($cfg['returnto_conf']) && $cfg['returnto_conf'] != '') {
header('Location: '.$cfg['returnto_conf']);
}
else {
printf($cfg['template'], 'Awaiting confirmation', 'An email has been sent to your address, '.$addr.', with a URL you must visit to confirm your subscription.');
}
}
else {
// problem with subscription
echoerr($err);
}
}
elseif ($type == 'unsub') {
// unsubscribe address
$f = openfile($cfg['listfile']);
$exists = false;
while ($item = readitem($f)) {
if ($item['addr'] == $addr) {$exists = true;break;}
}
if ($exists) {
delitem($f, $item['id']);
}
else {
$err = 'That address was not found.';
}
if (!isset($err)) {
// unsubscribe successful
if (isset($cfg['returnto_unsub']) && $cfg['returnto_unsub'] != '') {
header('Location: '.$cfg['returnto_unsub']);
}
else {
printf($cfg['template'], 'Unsubscribed', 'Your address, '.$addr.' has successfully been unsubscribed from our mailing list.');
}
}
else {
// problem with unsubscription
echoerr($err);
}
}
elseif ($type == 'confirm') {
// subscribe a confirmed address
if (!preg_match('#^([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+[^\".,?! ])$#i', $addr)) {
$err = 'Your email address appears to be invalid. If you are pasting the URL from your confirmation email, make sure the URL wasn\'t split into two lines.';
}
if (!isset($err)) {
$f = openfile($cfg['listfile']);
$exists = false;
while ($item = readitem($f)) {
if ($item['addr'] == $addr) {$exists = true;break;}
}
if ($exists) {
$err = 'That address is already subscribed to the list.';
}
}
if (!isset($err)) {
// subscribe successful
writeitem($f, $addr);
if (isset($cfg['returnto_sub']) && $cfg['returnto_sub'] != '') {
header('Location: '.$cfg['returnto_sub']);
}
else {
printf($cfg['template'], 'Subscribed', 'Your address, '.$addr.', is now subscribed to our mailing list!');
}
}
else {
// problem with subscription
echoerr($err);
}
}
function echoerr($err) {
printf($GLOBALS['cfg']['template'], 'Error', '<font color="red">Error: '.$err.'</font>');
}
?>