[SOLVED] sending file located on server
Posted: Tue Sep 07, 2004 2:16 pm
Mailing a document which is already on the server.
I wouldnt have trouble sending a attachment if it was to be uploaded, however i am trying to send a file that is already on the server.
this is how i am tring it to do.. but it doesnt work. the attachment is not being included.
I wouldnt have trouble sending a attachment if it was to be uploaded, however i am trying to send a file that is already on the server.
this is how i am tring it to do.. but it doesnt work. the attachment is not being included.
Code: Select all
<?
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/db.inc');
if (isset($_POST['submit']))
{
print_r($_POST);
$header = "From: " . $from . "\n";
if ($attachement != "none")
{
// Get attachement type
$type = $_FILES[attachement][type];
if (($type == "text/plain") || ($type == "text/html"))
$encoding = "8bit";
else
$encoding = "base64";
// Get attachement content
$fp = @fopen($_FILES[attachement][tmp_name],"r");
if (!$fp) {
print "Could not open attachment for reading...<br>\n";
print "Exiting script!<br><br>";
print "No mail has been sent!";
exit;
}
$file_content = fread($fp,filesize($_FILES[attachement][tmp_name]));
// if encoding is base64 ... encode it
if ($encoding == "base64")
$file_content = chunk_split(base64_encode($file_content));
// create a unqiue boundary
$boundary = strtoupper(md5(uniqid(time())));
// create the message header...
$header .= "MIME-version: 1.0\n";
$header .= "Content-Type: multipart/mixed;\n";
$header .= "\tboundary= " . $boundary . "\n\n";
$header .= "This is a multi-part message in MIME format.\n\n";
// create the message body in the header
$header .= "--" . $boundary . "\n";
$header .= "Content-Type: " . $ct . ";\n";
$header .= "\tcharset="iso-8859-1"\n";
$header .= "Content-Transfer-Encoding: quoted-printable\n\n";
// actual message
$header .= $body . "\n\n";
// now for the attachement
$header .= "--" . $boundary . "\n";
$header .= "Content-Type: " . $type . "\n";
$header .= "Content-Transfer-Encoding: " . $encoding . "\n";
$header .= "Content-Disposition: attachment; filename="" . $_FILES[attachement][name] . ""\n\n";
// actual attachement
$header .= $file_content . "\n\n";
$header .= "--" . $boundary . "--";
}
else // if there is no attachement...
{
$header .= "Content-Type: " . $ct . ";\n";
$header .= "\tcharset="iso-8859-1"\n";
$header .= "Content-Transfer-Encoding: quoted-printable\n\n";
// actual message
$header .= $body . "\n\n";
}
if (@mail($_POST['to'],$subject,"",$header))
print "Mail sent!";
else
print "Error sending email!";
}
else
{
session_start();
$query ='SELECT * FROM vacante WHERE unique_id="'.$_GET['ref'].'" AND vac_id="'.$_GET['vac_id'].'"';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
$query_cur ='SELECT * FROM archivos WHERE unique_id="'.$_SESSION['unique_id'].'"';
$result_cur = mysql_query($query_cur);
while($row_cur = mysql_fetch_assoc($result_cur)) {
?>
<html>
<head>
<title>Mail Attachement</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<form enctype="multipart/form-data" action="<?$_SERVER['PHP_SELF']?>" method="post">
<table width="500" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="150" align="left" valign="center">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
To:
</font>
</td>
<td width="350" align="left" valign="center">
<input type="hidden" size="40" name="to" value="<?echo $row['email_vac'];?>"><? echo $_GET['vac_id'];?>
</td>
</tr>
<tr>
<td width="150" align="left" valign="center">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
From:
</font>
</td>
<td width="350" align="left" valign="center">
<input type="text" size="40" name="from">
</td>
</tr>
<tr>
<td width="150" align="left" valign="center">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
Subject:
</font>
</td>
<td width="350" align="left" valign="center">
<input type="text" size="40" name="subject">
</td>
</tr>
<tr>
<td width="150" align="left" valign="center">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
Content type:
</font>
</td>
<td width="350" align="left" valign="center">
<select name="ct">
<option value="text/plain">Plaintext</option>
<option value="text/html">HTML mail</option>
</select>
</td>
</tr>
<tr>
<td width="150" align="left" valign="top">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
Message body:
</font>
</td>
<td width="350" align="left" valign="top">
<textarea rows="8" cols="38" name="body"></textarea>
</td>
</tr>
<tr>
<td width="150" align="left" valign="center">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
Attachement:
</font>
</td>
<td width="350" align="left" valign="center">
<input type="hidden" name="attachement" value="<? ECHO 'http://'.$_SERVER['HTTP_HOST']."/".$row_cur['archivo'];?>"><? ECHO $row_cur['archivo'];?>
</td>
</tr>
<tr>
<td width="150" align="left" valign="center">
<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000">
</font>
</td>
<td width="350" align="left" valign="center">
<input type="submit" value="Send" name="submit">
</td>
</tr>
</table>
</center>
</form>
</body></html>
<?
}
}
}
?>