使用联系表单发送附件 [英] Sending attachments with a contact form
问题描述
有什么想法吗?文件上传但它没有到达我的收件箱?
Any ideas? the file uploads but it doesnt arrive in my inbox?
$ errors ='';
$ jodie @ fuse9.co.ukl @ email.com'; //< -----把你的电子邮件地址放在这里。
if(空($ _ POST ['name2'])||
为空($ _ POST ['email2'])||
为空($ _ POST ['message2']))
{
$ errors。=\ n错误:所有字段都是必填字段;
} < br $>
$ name = $ _POST ['name2'];
$ email_address = $ _POST ['email2'];
$ message = $ _POST ['message2'];
if(!preg_match(
/^[_a-z0-9- ]+(\。[_ az0- 9 - ] +)* @ [a-z0-9 - ] +(\。[a-z0-9 - ] +)*(\。[az] {2,3})$ / i,
$ email_address))
{
$ errors。=\ n错误:电子邮件地址无效;
}
if(空($ errors))
{
$ to = $ myemail;
$ email_subject =联系表格提交:$ name;
$ email_body =您收到了一条新消息。。
以下是详细信息:\ n名称:$ name \ n电子邮件:$ email_address \\\
消息\ n $ message;
$ headers =From:$ myemail\\\
;
$ headers。=回复:$ email_address;
邮件($ to,$ email_subject,$ email_body,$ header );
//重定向到'谢谢'页面
标题('位置:contactos.html');
}
$ allowedExts = array(gif,jpeg,jpg,png);
$ temp = explode(。,$ _FILES [file] [name]);
$ extension = end($ temp);
if(($ _FILES [file] [type] ==image / gif)
||($ _FILES [file] [type] == image / jpeg)
||($ _FILES [file] [type] ==image / jpg)
||($ _FILES [ file] [type] ==image / pjpeg)
||($ _FILES [file] [type] ==image / x-png)
||($ _FILES [file] [type] ==image / png))
&&($ _FILES [file ] [尺寸]< 20000)
&& in_array($ extension,$ allowedExts))
{
if ($ _FILES [file] [error]> 0)
{
echo错误:。 $ _FILES [file] [error]。
;
}
其他
{
echo上传:。 $ _FILES [file] [name]。
;
echo类型:。 $ _FILES [file] [type]。
;
echo大小:。 ($ _FILES [file] [size] / 1024)。 kB
;
echo存储于:。 $ _FILES [file] [tmp_name];
}
}
else
{
echo文件无效;
}
?>
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Transitional // ENhttp://www.w3.org/TR/html4/loose.dtd\">
< html>
< head>
< title>发送邮件全球上传< / title>
< / head>
< body>
<! - 只有在出现错误时才会显示此页面 - >
echo nl2br($ errors);
?>
< / body>
< / html>
$errors = '';
$jodie@fuse9.co.ukl@email.com';//<-----Put Your email address here.
if(empty($_POST['name2']) ||
empty($_POST['email2']) ||
empty($_POST['message2']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name2'];
$email_address = $_POST['email2'];
$message = $_POST['message2'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contactos.html');
}
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "
";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "
";
echo "Type: " . $_FILES["file"]["type"] . "
";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB
";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
}
else
{
echo "Invalid file";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>send mail global upload</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
echo nl2br($errors);
?>
</body>
</html>
推荐答案
errors ='';
errors = '';
jodie @ fuse9.co.ukl @ email.com'; //< -----将您的电子邮件地址放在这里。
if(空(
jodie@fuse9.co.ukl@email.com';//<-----Put Your email address here.
if(empty(
_POST ['name2'])||
为空(
_POST['name2']) ||
empty(
这篇关于使用联系表单发送附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!