How can I add file attachment to my form and get the attachment by email?
i'm using code , works fine, don't attachment file in email. how can add code?
html
__________________________________
<!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=utf-8" />
<title>untitled document</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">// <![cdata[
$(document).ready(function() {
$("#form1").validate({
rules: {
first: "required",// simple rule, converted {required:true}
email: {// compound rule
required: true,
email: true
},
last: {
last: true
},
comment: {
required: true
}
},
messages: {
comment: "please enter comment."
}
});
});
// ]]></script>
<script type="text/javascript">// <![cdata[
function validate ()
{
if (document.form1.first.value == "")
{
alert("please enter first name");
document.form1.first.focus();
document.form1.first.style.border="1px solid red";
return false;
}
else if (document.form1.last.value == "")
{
alert("please enter last name");
document.form1.last.focus();
document.form1.last.style.border="1px solid red";
return false;
}
else if (document.form1.emailaddress.value == "")
{
alert("please enter email address");
document.form1.emailaddress.focus();
document.form1.emailaddress.style.border="1px solid red";
return false;
}
}
function has_focus() {
if(document.form1.first.value == "")
{
document.form1.first.focus();
document.form1.style.first.border="1px solid green";
}
}
function set_focus(x)
{
document.getelementbyid(x).style.border="1px solid #80ca75";
}
function clear_focus(x)
{
document.getelementbyid(x).style.border="1px solid #dbdfe6";
}
// ]]></script>
</head>
<body>
<p><span style="color: #666666; text-align: center; font-size: 13px;">please complete form if have technical issue.</span></p>
<form id="form1" action="http://www.southsun.com/php/tech_issue.php" enctype="multipart/form-data" method="post">
<table style="width: 850px; font-size: 15px; padding-left: 20px; text-align: center;" border="0">
<tbody>
<tr>
<td style="text-align: left; padding-bottom: 20px;" colspan="2">
<h2><span style="color: #666666;">please complete form if have technical issue.</span></h2>
</td>
</tr>
<tr style="padding-top: 40px;">
<td style="text-align: left;"><span style="color: #abaf6f;"><strong>first name</strong>:*</span><input id="first1" name="first" type="text" /> <br /><br /> <span style="color: #abaf6f;"><strong>last name</strong>:*</span><input id="last1" name="last" type="text" /><br /><br /> <span style="color: #abaf6f; padding-right: 33px;"><strong>email</strong>:</span><span style="color: #abaf6f;">*</span><input id="email1" name="email" type="text" /><br /><br /> <span style="color: #abaf6f;"><strong>shipping method:</strong><br /></span> <input name="shippingmethod" type="radio" value="prioritymail" /> priority mail <input name="shippingmethod" type="radio" value="store" /> in store pick <br /> <input name="shippingmethod" type="radio" value="ground" /> ground <input name="shippingmethod" type="radio" value="3day" /> 3 day select<br /><br /> <span style="color: #abaf6f;"><strong>payment method:</strong><br /></span> <input name="paymentmethod" type="radio" value="paypal" /> paypal method <input name="paymentmethod" type="radio" value="creditcard" /> credit card<br /> <strong><br /> <span style="color: #abaf6f;">if getting error message, please explain error:</span></strong><span style="color: #abaf6f;"> <br /></span> <textarea id="errormessage" cols="20" rows="2" name="errormessage"></textarea><br /><br /></td>
<td style="border-left: 1px solid grey; padding-left: 40px; text-align: left;"><span style="color: #abaf6f;"><strong>if using paypal, redirected successfully?</strong><br /></span> <input name="paypalredirect" type="radio" value="yes" /> yes <input name="paypalredirect" type="radio" value="no" /> no<br /><br /> <span style="color: #abaf6f;"><strong>if using credit card, did error?</strong><br /></span> <input name="carderror" type="radio" value="yes" /> yes <input name="carderror" type="radio" value="no" /> no<br /><br /> <span style="color: #abaf6f;"><strong>what happened after clicking place order? </strong><br /></span> <textarea id="placeorder1" cols="20" rows="2" name="placeorder"></textarea><br /><br /> <span style="color: #abaf6f;"><strong>comments</strong>: <br /></span> <textarea id="comments1" cols="20" rows="2" name="strcomments"></textarea><br /><br /> <span style="color: #abaf6f;"><strong>attach printscreen</strong>: <br /></span> <input name="strresume" type="file" />
<div style="height: 50px;"> </div>
</td>
</tr>
<tr>
<td style="padding-top: 20px;" colspan="2">( * ) indicates required fields</td>
</tr>
<tr>
<td style="text-align: center; padding-top: 20px;" colspan="2"><input class="button" name="submit" type="submit" value="submit" /> <input class="button" name="reset" type="reset" value="reset" /></td>
</tr>
</tbody>
</table>
</form>
</body></html>
____________________________________________
php
____________________
<?php
echo $savestring;
//--------------------------paramaters--------------------------
// subject of email sent you.
$subject = 'prueba con uploads';
// email address. form information sent.
$emailadd = 'pchinique@yahoo.com';
// redirect after form processed.
$url = 'http://www.pch-graphicdesign.com';
// makes fields required. if set '1' no field can not empty. if set '0' or fields can empty.
$req = '0';
$target_path = "http://www.pch-graphicdesign.com/php/uploads/";
$target_path = $target_path . basename( $_files['uploadedfile']['name']);
$text = "results form:\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 = ' ';
}
mail($emailadd, $subject, $text, 'from: '.$emailadd.'');
echo '<meta http-equiv=refresh content="0; url='.$url.'">';
?>
sending file attachment email involves setting correct mime type , headers. there's brief tutorial here: http://webcheatsheet.com/php/send_email_text_html_attachment.php.
also, need use same name in form. in script have shown here, name of file field strresume, processing script uses this: $_files['uploadedfile']['name']. should this: $_files['strresume']['name']
More discussions in Develop server-side applications in Dreamweaver
adobe
Comments
Post a Comment