this is my code.i m trying send mail with attachment(word,excel,pdf,etc....any attachment)plz help me how to attach file...mailing list from database(mysql)...thanks in advance
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Send e-mails</title>
<?php
$from = "mail@mail.com";
$mesa = $_POST['mess'];
$subje = $_POST['subj'];
$mails = $_POST['mail'];
?>
<link rel="stylesheet" href="stylesheet.css"> <!-- Main Stylesheet -->
</head>
<body style="margin: 1px; font-family: arial, verdana, san-serif; font-size: 14px;">
<table width="80%" border="1" align="center">
<tr>
<td><div align="right">
Add new e-mail <a href="index1.php"><font color=#005aee>Here</font></a> <a href='logout.php'>Logout</a></div>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<table>
<tr>
<td>
<form name=mailids>
<select name=test multiple size=26 style="width: 200px;">
<?php
include("connect.php");
$query="SELECT email FROM emails ORDER BY email";
$rs = mysql_query($query);
while($row = mysql_fetch_array($rs))
{
echo"<option>".$row['email']."</option>";
}
?>
</select>
</form>
</td>
</tr>
</table>
</td>
<!-- To add required code to make the milids selected after sending mail -->
<!--script language=javascript>
document.mailids.test[0].selected = true;
</script-->
<td>
<table>
<tr>
<td>
<form name=message method=post action="<?php $PHP_SELF?>">
<br>
FROM :<br>
<input name=from value=<?php echo "$from";?> type=text size=59 readonly>
<br><br>
Subject:<br>
<input name=subj value="<?php echo($subje); ?>" type=text size=59><br><br>
Message:<br>
<textarea name="mess" rows=16 cols=50 wrap=physical><?php echo($mesa); ?></textarea>
<input type=hidden name=mail>
<br><br>
Attach File:
<input type="file" name="uploaded_file">
<br><br>
<input type=submit value="Send Mail" onClick="submitForm()">
</form>
<script language=javascript>
function submitForm()
{
var subject = document.message.subj.value;
if(subject.length == "")
{
alert("Please give a proper subject");
return false;
}
var message = document.message.mess.value;
if(message.length == "")
{
alert("Please give a proper message");
return false;
}
var tot = document.mailids.test.length;
var maildis = "";
for(i=0; i<tot; i++)
{
if(document.mailids.test[i].selected == true)
{
var ssr = document.mailids.test[i].value;
maildis = maildis+"||"+ssr;
document.message.mail.value = maildis;
}
}
var maaa = document.message.mail.value;
echo(maaa);
document.message.submit();
}
</script>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<?php
$tok = strtok($mails, " ||");
echo("Mail sent to:");
$message1 = str_replace("<br />", "\n", $mesa);
$message1 = str_replace("\\\\","",$message1);
$message1 = str_replace("\'","'",$message1);
$message1 = str_replace("\\\"","\"",$message1);
$message1 = nl2br($message1);
while ($tok)
{
/* additional headers */
/* To send HTML mail, you can set the Content-type header. */
$random_hash = md5(date('r', time()));
$headers1 = "MIME-Version: 1.0\r\n";
$headers1 .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers1 .= "To: ".$tok."\r\n";
$headers1 .= "From: ".$from."\r\n";
$headers1 .= "Reply-To: ".$from."\r\n";
$headers1 .= "Cc: \r\n";
echo("<font color=green> $tok </font>");
if(@mail($tok,$subje,$message1,$headers1))
{
echo("-<font color=#005aee> Mail Sent Successfully </font>,");
}
else
{
echo("-<font color=red>Mail Not Sent </font>,");
}
$tok = strtok("||");
}
?>
</td>
</tr>
</table>
</body>
</html>