To jest cały kod:
<?
include "config.php";
require_once ('../header.php');
?>
<!-- thank-you -->
<section id="media" class="content-section text-center">
<div class="media-pg">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Newsletter</h2>
<?
function sendmail($mail) {
$res = mysql_query("SELECT Token FROM newsletter where address = \"".$mail."\" ");
$message='<p>Welcome to domain.com newsletter system. To confirm your e-mail, click the link below:<br />
<a href="http://annoncube.com/newsletter/confirm.php?address='.$mail.'&token='.$token.'">http://domain.com/newsletter/confirm.php?address='.$mail.'&token='.$token.'</a><br /><br />
If you do not want to join this newsletter, ignore this message.<br /><br />
Please do not reply to this message was generated automatically</p>';
$subject = 'Newsletter - Domain.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From:' . "noreply@domain.com\r\n";
mail($mail,$subject,$message,$headers);
}
$mail=$_POST['newsletter'];
if($mail == NULL){
?>
<p style="padding-bottom:250px;">
Not entered an email address!
</p>
<?
}
else{
$result1 = @mysql_query("INSERT INTO newsletter (Address,Token) VALUES (\"".$mail."\", \"".$token."\") ");
if ($result1) {
?>
<p style="padding-bottom:250px;">
Thank you for your subscribe!
</p>
<?
sendmail($mail);
}
else{
$result2 = mysql_query("SELECT Confirmed FROM newsletter where Address = \"".$mail."\" "); if($confirm == "y"){
?>
<p style="padding-bottom:250px;">
E-mail address already exists in the database and is confirmed
</p>
<?
}
else if($confirm == "n"){
?>
<p style="padding-bottom:250px;">
E-mail address already exists in the database but isn't confirmed
</p>
<?
}
}
}
?>
</div>
</div>
</div>
</div>
</section>
<?
require_once ('../footer.php');
?>
MySQL:
CREATE TABLE `newsletter` (
`ID` smallint(5) UNSIGNED NOT NULL,
`Address` varchar(200) NOT NULL,
`Confirmed` enum('y','n') NOT NULL DEFAULT 'n',
`Token` varchar(40) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Address` (`Address`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Dodam, że kod działa tylko dla pierwszego użytkownika, Później wywala błąd