如何以网络表单上传文件并通过电子邮件发送?
我正在尝试创建 RMA 表单,除了上传 + 电子邮件附件之外,一切正常。
我想做的是让客户上传他们文档的扫描副本(jpeg、gif、png、pdf、word 等格式),但我似乎无法让事情顺利进行。我正在尝试各种文件上传方法,但我似乎不知道从哪里开始。
这是到目前为止我的 php 代码
$name=$_POST['first'] ." ".$_POST['last'];
$email=$_POST['email'];
$address=$_POST['street'] ." ". $_POST['city'] ."".$_POST['province'] ." ".$_POST['postal'];
$pod=$_POST['pod'];
$sku=$_POST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$case_id=$_POST['case_id'];
$status=$_POST['status'];
$phone=$_POST['parea'] ."".$_POST['pfirst'] ."".$_POST['plast'];
$tracking=$_POST['tracking'];
$date=$_POST['date'];
$link = mysql_connect('m', 'sk', 's1');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(s);
$status = "Pending";
$tracking = "";
$date = date('c');
$case_id = mt_rand(1252,10000);
while( $fetch = mysql_fetch_array( mysql_query("SELECT `case_id` FROM `webform` WHERE `case_id` = $case_id") ) )
{
$case_id = mt_rand(1252,10000);
}
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ($name,$phone,$email,$address,$pod,$sku,$description,$problem);
$required = array($name,$phone,$email,$address,$pod,$sku,$description,$problem);
$your_email = "[email protected]";
$email_subject = "RMA: ".$case_id;
$email_content = "new message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != $phone && $key != $address)
$email_content .= $value.' '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content,$case_id)) {
echo 'Request Submitted!<br />';
echo 'RMA:'. $case_id;
} else {
echo 'ERROR!';
}
}
$queries = array ($values, $case_id);
$piece = implode(",",$queries);
mysql_query("INSERT INTO `webform` (`case_id`, `name`, `phone`, `email`, `address`, `pod`, `sku`, `description`, `problem`, `status`, `tracking`, `date_recieved`) VALUES ('$case_id', '$name', '$phone', '$email', '$address', '$pod', '$sku','$description', '$problem', '$status', '$tracking', '$date')")
or die(mysql_error());
mysql_close($link);
?>
所以基本上,我不知道在哪里放置文件上传部分,甚至不知道如何使用它。我有一个有效的 html 设计,可以打开文件浏览器和所有内容,我只是不知道如何将该进程链接到 php 端,然后在上传后将其附加到电子邮件中。
预先感谢大家的帮助!
I'm trying to create an RMA form and I have everything working except the upload + email attachment.
What I'm trying to do is have the customer upload a scanned copy of their document (in jpeg,gif,png,pdf,word etc formats) but I can't seem to get things going. I'm up on various file upload methods, but I can't seem to figure out where to begin.
This is my php code so far
$name=$_POST['first'] ." ".$_POST['last'];
$email=$_POST['email'];
$address=$_POST['street'] ." ". $_POST['city'] ."".$_POST['province'] ." ".$_POST['postal'];
$pod=$_POST['pod'];
$sku=$_POST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$case_id=$_POST['case_id'];
$status=$_POST['status'];
$phone=$_POST['parea'] ."".$_POST['pfirst'] ."".$_POST['plast'];
$tracking=$_POST['tracking'];
$date=$_POST['date'];
$link = mysql_connect('m', 'sk', 's1');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(s);
$status = "Pending";
$tracking = "";
$date = date('c');
$case_id = mt_rand(1252,10000);
while( $fetch = mysql_fetch_array( mysql_query("SELECT `case_id` FROM `webform` WHERE `case_id` = $case_id") ) )
{
$case_id = mt_rand(1252,10000);
}
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ($name,$phone,$email,$address,$pod,$sku,$description,$problem);
$required = array($name,$phone,$email,$address,$pod,$sku,$description,$problem);
$your_email = "[email protected]";
$email_subject = "RMA: ".$case_id;
$email_content = "new message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != $phone && $key != $address)
$email_content .= $value.' '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content,$case_id)) {
echo 'Request Submitted!<br />';
echo 'RMA:'. $case_id;
} else {
echo 'ERROR!';
}
}
$queries = array ($values, $case_id);
$piece = implode(",",$queries);
mysql_query("INSERT INTO `webform` (`case_id`, `name`, `phone`, `email`, `address`, `pod`, `sku`, `description`, `problem`, `status`, `tracking`, `date_recieved`) VALUES ('$case_id', '$name', '$phone', '$email', '$address', '$pod', '$sku','$description', '$problem', '$status', '$tracking', '$date')")
or die(mysql_error());
mysql_close($link);
?>
So basically, I'm not sure where to place the file upload section or even how to use it. I have a working html design for it that brings up the file browser and everything, I just don't know how to link that process to the php side, and then after uploading attach that to the email.
Thank you kindly in advance for everyone's help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会。
我的公司每月发送数百万封电子邮件,而电子邮件附件是我们面临的最大问题。最重要的是,您附加了一些内容,并且大大增加了被阻止或标记为垃圾邮件的机会。
改为发送链接。在链接中使用唯一的哈希标识符,用户可以单击该标识符来启动下载。它可以让电子邮件变得更小、更容易发送垃圾邮件、更轻松地编码以及让客户更满意。
I wouldn't.
My company sends millions of emails monthly and email attachments are the biggest single problem that we have. Bottom line, you attach things and you raise the chances of being blocked or flagged for spam by a significant factor.
Send a link instead. Use a unique hash identifier in the link that the person can click to initiate a download. It makes for a smaller email, more spam friendly delivery, easier coding for you, and happier customers.
我专门使用这个,它对我很有帮助。
http://formtoemail.com/
I use this exclusively and it has served me very well.
http://formtoemail.com/