Hey Guys,
I am writing this code to send out personalised emails to potential customers. And i have few questions about the code. This code is made from several tutorials and code examples. I have searched for stuff on it and theres plenty of articles about it but not what i want to do.
If anyone knows of one please throw us a link.
This has two pages the first is just a basic form to fill in the subject thats it really. And the second is below.
I'll reference the question next to the code its related to. :)
Q1. Is this line and Q2 related or should they be related?
Q2. What do these two lines do and what are they meant to do? They don't make sense to me but i've rechecked the tutorial and thats whats there? Along with the fact the varible $email isn't assigned to anything(Im gettin an erroe for it at the moment.)?
Q3. This bit of code is working but not correctly all i get when i view the emails (i am just testing by sending 4 emails at the moment) is the first name from the first person in the database?
<?php
// Check, if submitted.
//if($submit)
if(isset($_POST['submit'])){
// Get variables from POST method form.
$subject=$_POST['subject'];
//$note=$_POST['note'];
Q1. line below
$sender="***********"; // Your Email here.
echo "Email has been sent to:";
// Connect database
mysql_connect("localhost","root","");
mysql_select_db("******");
$rs=mysql_query("select * from mailList LIMIT 20 ");
// if (!$query) die(mysql_error());
// Do while loop to send email.
while($row=mysql_fetch_assoc($rs)){
$to=$row['email'];
Q2. lines below
$mail_from="From:$email n";
$mail_from .="Content-Type: text/html; charset=utf-8 n";
Q3.lines below
$note .= "<p>Hi ".$row['owner']." <br /><br />";
$note .="";
mail($to,$subject,$note,$mail_from);
// Show sent emails.
echo "$row[email]<br>";
}
}
else{
// Do following codes if not found "Submit" value.(Not submitted)
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<title>Email Form</title>
<body>
<form action="<? echo $PHP_SELF; ?>" method="post" name="form" id="form">
<table>
<tr>
<td align="right">Subject : </td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td align="right" valign="top">Note : </td>
<td><textarea name="comment" cols="60" rows="5" id="comment"></textarea></td>
</tr>
</table>
<input type="submit" name="Submit" value="Send Email" />
</form>
</body>
</html>
<?php } ?>
Any help will be greatly appreciated.
Thanks in advance.