I have been trying to set up a newsletter sign up system so that a user can register their email and the admin can send a newsletter from the actual web site. However, the problem is that the newsletter does not send to the email address.
here is my code:
the form
<form NAME="newsletter" onSubmit="return ValidateForm()" METHOD="POST" ACTION="newsletter.php">
<p class="clearfix"><label for="email">Your E-mail</label>
<input name="email" id="email" type="text" value="" /></p>
<p class="clearfix check"> </p>
<span class="clearfix check">
<input type="Submit" value="Submit" name="SubmitButton" />
</span>
</form>
newsletter.php
<?php
include ("connection.php");
$status = "OK";
$msg = "";
if(!stristr($email,"@")OR !stristr($email,".")){
$msg = "Your email address is not valid<BR>";
$status = "NOT OK";}
echo "<br><br>";
if($status=="OK"){
$query=("INSERT INTO newsletter (email,status) VALUES ('$email','subscribe')");
$result=mysql_query($query);
echo "<center>THANK YOU <br>Thanks for subscribing to our newsletter. At any time you can unsubscribe by clicking a link in your newsletter</center>";
}
else {echo "<center>$msg </center>";}
?>
form to send newsletter
<form name="booking" action="postmail.php" method="post">
<label><span>Subject of Message</span>
<input type="text" name="subject" id="subject" class="input-text"/>
</label>
<label><span>Message Body</span>
<textarea name="body" id="body" cols="35" rows="10"></textarea>
</label>
<input type=hidden name=sendmail value=yes>
<div class="spacer"><input type="submit" value="Send" class="green"></div>
</form>
postmail.php
<?php
include ("connection.php");
$pt2="http:// $hostname$databaseName";
$pt2= substr($pt2,0,strlen($pt2)-21);
$query="select email from newsletter where status='subscribe'";
$result=mysql_query($query);
while($rowdata=mysql_fetch_array($result))
{
$msg2=$msg."<BR>To unsubscribe <a href=$pt2"."unsub.php?email=$rowdata[em]>Click HERE</a>";
mail($rowdata[email],$subject, $body, $msg2,"$mail_type");
}
?>
Any help would be much appreciated. 🙂