Hello,
My ultimate goal is to be able to browse a particular folder, select any file from that folder & send it via email to someone. With that in mind, this is what I've done so far.
I've designed the form which automatically browses the appropriate folder & displays all the files inside. This form seems to be working fine. My code is displayed below.
The form action points towards another php file called email_sender.php where all the magic takes place. This form seems to be working fine as well. My code is displayed below as well.
My question is:-
How do I get the script to email me the file I selected as an attachment?
I suspect that:-
1. I may not have designed the form properly.
2. I need to declare the selected file as a variable in email_sender.php which I do not know how to do.
3. I need to insert that variable into the mail function which I also do not know how to do.
4. I may have to declare a header or something like that.
Could you tell me what I need to do? Thank you very much for your advice.
Code for the form:-
<?php
if ($dir = @opendir("/home/someone/domains/someone.com/file_emailer"))
{
while (($file = readdir($dir)) !== false)
{
if($file != ".." && $file != ".")
{
$filelist[] = $file;
}
}
closedir($dir);
}
?>
<form name="form1" method="post" action="email_sender.php">
<form>
<select name="selected_dir" >
<?php
asort($filelist);
while (list ($key, $val) = each ($filelist))
{
echo "<option>$val</option>";
}
?>
</select>
<label>
<input name="email1" type="text" id="email1" value="Enter your email here" />
</label>
<label>
<input name="Submit1" type="submit" id="Submit1" value="Submit" />
</label>
</form>
</form>
Code for email_sender.php:-
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<?php
$username="abc123";
$password="abc123";
$database="abc123";
$host="localhost";
$email1=$_POST['email1'];
$Submit1=$_POST['Submit1'];
if(isset($Submit1))
{
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
$query=mysql_query("SELECT * FROM customers WHERE email = '$email1'");
$numrows=mysql_num_rows($query);
if ($numrows>0)
{
$data=mysql_fetch_array($query);
$from ='someone@someone.com';
$to = $data["email"];
$name = $data["name"];
$subject = "Your file request";
$body="Hello ". $name .",\nHere's your file
\nBest of luck to you in all your appointments tommorrow :-)
\nWarm Regards\n\nsomeone\n+999 9999";
mail($to,$subject,$body,"From: someone@someone.com", "-fsomeone@someone.com");
echo "Your e-mail has been sent";
}
else
{
echo "Your subscription has probably expired.";
}
}
?>
</body>
</html>