My ultimate goal is to browse a particular folder, select a file & send it as an email attachment to someone. With that in mind, I have designed a form. The form works fine. I've included the code here just to give you the total picture of what I'm doing.
The form action points towards another file called email_sender.php where all the magic happens. This is where I need help. I've included the code below as well.
My question is:-
How do I send the selected file as an email attachment?
I'm a newbie who does not understand much technical jargon. I've seen quite a number of samples on many forums but I don't understand the technical jargon. This code I wrote is actually based on my copy & paste activities so I don't actually understand how it works, but it works
The code for the form:-
Code: Select all
<?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: Select all
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<?php
$username="abc123";
$password="abc123";
$database="abc123";
$host="localhost";
$selected_dir=$_POST['selected_dir'];
$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";
$headers = "$selected_dir";//I suspect more stuff needs to be added here.
$body="Hello ". $name .",\nHere's your file
\nBest of luck to you in all your appointments tommorrow :-)
\nWarm Regards\n\nsomeone\nsomeone";
mail($to,$subject,$body,$headers,"-fsomeone@someone.com");
echo "Your e-mail has been sent";
}
else
{
echo "Your subscription has probably expired.";
}
}
?>
</body>
</html>