PHP Email Attachment Trouble Shooting
i having problems finding example php script send attachment in email form. have written many scripts. can me? attach current script below.
<?php
$subject = 'online application candidate';
$emailadd = 'kuronk@duq.edu';
$url = 'http://www.mydomain.com/form/application_recieved.htm';
$req = '0';
$mime_boundary="==multipart_boundary_x".md5(mt_rand())."x";
$tmp_name = $_files['file']['tmp_name'];
$type = $_files['file']['type'];
$name = $_files['file']['name'];
$size = $_files['file']['size'];
$text = "mime-version: 1.0\r\n" .
"content-type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
"--{$mime_boundary}\n" .
"content-type: text/plain; charset=\"iso-8859-1\"\n" .
"content-transfer-encoding: 7bit\n\n" .
$text . "\n\n";
"--{$mime_boundary}\n" .
"content-type: {$type};\n" .
" name=\"{$name}\"\n" .
"content-disposition: attachment;\n" .
" filename=\"{$form_attachments}\"\n" .
"content-transfer-encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$text = "application results:\n\n";
$space = ' ';
$line = '
';
foreach ($_post $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "name of form element $key cannot longer 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
function heal($str) {
$injections = array('/(\n+)/i',
'/(\r+)/i',
'/(\t+)/i',
'/(%0a+)/i',
'/(%0d+)/i',
'/(%08+)/i',
'/(%09+)/i'
);
$str= preg_replace($injections,'',$str);
return $str;
}
function isinjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0a+)',
'(%0d+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
$allowedexts = array("doc", "docx", "xml", "xls", "xlsx", "pdf");
$extension = end(explode(".", $_files["file"]["name"]));
if ((($_files["file"]["type"] == "application/doc")
|| ($_files["file"]["type"] == "application/docx")
|| ($_files["file"]["type"] == "application/xml")
|| ($_files["file"]["type"] == "application/xls")
|| ($_files["file"]["type"] == "application/xlsx")
|| ($_files["file"]["type"] == "application/pdf"))
&& ($_files["file"]["size"] < 20000)
&& in_array($extension, $allowedexts))
{
if ($_files["file"]["error"] > 0)
{
echo "return code: " . $_files["file"]["error"] . "<br />";
}
else
{
echo "upload: " . $_files["file"]["name"] . "<br />";
echo "type: " . $_files["file"]["type"] . "<br />";
echo "size: " . ($_files["file"]["size"] / 1024) . " kb<br />";
echo "temp file: " . $_files["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_files["file"]["name"]))
{
echo $_files["file"]["name"] . " exists. ";
}
else
{
move_uploaded_file($_files["file"]["tmp_name"],
"upload/" . $_files["file"]["name"]);
echo "stored in: " . "upload/" . $_files["file"]["name"];
}
}
}
else
{
echo "invalid file";
}
mail($emailadd, $subject, $text, 'from: '.$emailadd.'');
echo '<meta http-equiv=refresh content="0; url='.$url.'">';
?>
More discussions in Develop server-side applications in Dreamweaver
adobe
Comments
Post a Comment