coxdabd
12-04-2010, 10:27 AM
Hi there,
Trying to create a basic script to email across a users email address. That part was working. I also want it to check the database to see if their address is already in the database - though now nothing seems to be working. I'm sure it's just a small error.
Appreciate any help.
<?php
if ($_POST['email']!=""){
include('connection.php');
$email = mysql_real_escape_string($_POST['email']);
$result = mysql_query("SELECT * FROM addresses");
$num_rows = mysql_num_rows($result);
$sql = mysql_query("SELECT * FROM addresses WHERE email='$email'");
$numRow = mysql_num_rows($sql);
//Section to check for valid email address
if ($numRow>0){
exit();
}
else(false !== filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$sql_insert=mysql_query("INSERT INTO addresses (email, dateTime) VALUES('$email',now())") or die (mysql_error());
$to = "example@gmail.com";
$subj = "Newsletter Subscriber";
$headers = "From:info@test.com\r\n";
$headers .= "Content-type: text/html\r\n";
$content = "Hi,<br><br>A new address ($email) has been added to the newsletter database.<br><br>There is now a total of <strong>$num_rows</strong> email addresses in the database.<br><br>Thanks,<br><br>The Computer<br><br><span style='font-size: 10px; color: #777777;'>This is an automated message, you do not need to reply or take any type of action. Do not reply to this message - no one will receive it!</span>";
mail($to, $subj, $content, $headers);
//Message to Subscriber
$toSub = $_POST['email'];
$subjSub = "Newsletter";
$headersSub = "From:info@test.com\r\n";
$headersSub .= "Content-type: text/html\r\n";
$contentSub = "Hi,<br><br>Thank you for subscribing to the Newsletter.<br><br>You will receiving your first newsletter from us soon.<br><br>Thanks,<br><br>Hello World";
mail($toSub, $subjSub, $contentSub, $headersSub);
}
}
?>
Trying to create a basic script to email across a users email address. That part was working. I also want it to check the database to see if their address is already in the database - though now nothing seems to be working. I'm sure it's just a small error.
Appreciate any help.
<?php
if ($_POST['email']!=""){
include('connection.php');
$email = mysql_real_escape_string($_POST['email']);
$result = mysql_query("SELECT * FROM addresses");
$num_rows = mysql_num_rows($result);
$sql = mysql_query("SELECT * FROM addresses WHERE email='$email'");
$numRow = mysql_num_rows($sql);
//Section to check for valid email address
if ($numRow>0){
exit();
}
else(false !== filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$sql_insert=mysql_query("INSERT INTO addresses (email, dateTime) VALUES('$email',now())") or die (mysql_error());
$to = "example@gmail.com";
$subj = "Newsletter Subscriber";
$headers = "From:info@test.com\r\n";
$headers .= "Content-type: text/html\r\n";
$content = "Hi,<br><br>A new address ($email) has been added to the newsletter database.<br><br>There is now a total of <strong>$num_rows</strong> email addresses in the database.<br><br>Thanks,<br><br>The Computer<br><br><span style='font-size: 10px; color: #777777;'>This is an automated message, you do not need to reply or take any type of action. Do not reply to this message - no one will receive it!</span>";
mail($to, $subj, $content, $headers);
//Message to Subscriber
$toSub = $_POST['email'];
$subjSub = "Newsletter";
$headersSub = "From:info@test.com\r\n";
$headersSub .= "Content-type: text/html\r\n";
$contentSub = "Hi,<br><br>Thank you for subscribing to the Newsletter.<br><br>You will receiving your first newsletter from us soon.<br><br>Thanks,<br><br>Hello World";
mail($toSub, $subjSub, $contentSub, $headersSub);
}
}
?>