Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过表单以附件形式邮寄文件_Php_Ajax_Forms_Email_Phpmailer - Fatal编程技术网

Php 通过表单以附件形式邮寄文件

Php 通过表单以附件形式邮寄文件,php,ajax,forms,email,phpmailer,Php,Ajax,Forms,Email,Phpmailer,因此,我目前正在使用一个HTML表单从客户处获取信息(在登录页上下文中),该表单通过电子邮件发送用户提交的所有信息,目前为止,该表单运行良好 然而,我已经在HTML表单($userfile)中添加了一个文件上传字段,但是我无法正确处理文件上传和附件。我已经测试和调整了很多,但我似乎从来没有得到它的工作 这是我目前正在使用的基于预先存在的模板的PHP文件 $to = "email@email.com"; $nome = $_POST["nome"]; $emai

因此,我目前正在使用一个HTML表单从客户处获取信息(在登录页上下文中),该表单通过电子邮件发送用户提交的所有信息,目前为止,该表单运行良好

然而,我已经在HTML表单($userfile)中添加了一个文件上传字段,但是我无法正确处理文件上传和附件。我已经测试和调整了很多,但我似乎从来没有得到它的工作

这是我目前正在使用的基于预先存在的模板的PHP文件

$to             = "email@email.com"; 

$nome     = $_POST["nome"];
$email    = $_POST["email"];
$website  = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if (isset($email) && isset($nome)) {
    $subject  = "Lead: $nome";
    $headers  = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "From: ".$nome." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
    $msg      = 'Hey Admin, <br/> <br/> Here are the details:';
    $msg     .= ' <br/> <br/> <table border="1" cellpadding="6" cellspacing="0" style="border: 1px solid  #eeeeee;">';
    foreach ($_POST as $label => $value) {
        $msg .= "<tr><td width='100'>". ucfirst($label) . "</td><td width='300'>" . $value . " </tr>";
    }
    $msg      .= " </table> <br> --- <br>Sent by $website";

    $mail =  mail($to, $subject, $msg, $headers);

    if($mail) {
            echo 'success';
    } else {
            echo 'failed';
    }

} // END isset

?>
$to=”email@email.com"; 
$nome=$_POST[“nome”];
$email=$_POST[“email”];
$WEBSET=(isset($_服务器['HTTPS'])?“HTTPS”:“http”)。“://$\u服务器[HTTP\u主机]$\u服务器[REQUEST\u URI]”;
if(isset($email)和isset($nome)){
$subject=“Lead:$nome”;
$headers=“MIME版本:1.0”。\r\n”;
$headers.=“内容类型:text/html;字符集=iso-8859-1”。\r\n”;
$headers.=“发件人:”.$nome.\r\n“。回复:“.$email.\r\n”;
$msg='嘿,管理员,

这里是详细信息:'; $msg.='

'; foreach($\发布为$label=>$value){ $msg.=''.ucfirst($label)。''.$value.''; } $msg.=“
--
由$website发送”; $mail=mail($to,$subject,$msg,$headers); 如果($邮件){ 呼应"成功",; }否则{ echo“失败”; } }//结束isset ?>
还有AJAX帖子

var dataString = $(form).serialize();

            /* 
             AJAX POST
             --------- */

            $.ajax({
                type: "POST",
                data: dataString,
                url: "php/contact.php",
                cache: false,
                success: function(d) {
                    $(".form-group").removeClass("has-success");
                    if (d == 'success') {
                        if (noredirect) {
                            $('#js-contact-result').fadeIn('slow').html('<div class="alert alert-success top-space">' + success_msg + '</div>').delay(3000).fadeOut('slow');
                        } else {
                            window.location.href = redirect;
                        }
                    } else {
                        $('#js-contact-result').fadeIn('slow').html('<div class="alert alert-danger top-space">' + error_msg + '</div>').delay(3000).fadeOut('slow');
                    }
                    $("#js-contact-btn").attr("disabled", false);
                }
            });
var-dataString=$(form).serialize();
/* 
阿贾克斯邮报
--------- */
$.ajax({
类型:“POST”,
数据:dataString,
url:“php/contact.php”,
cache:false,
成功:功能(d){
$(“.form group”).removeClass(“has success”);
如果(d==“成功”){
if(noredirect){
$('#js contact result').fadeIn('slow').html(''+success_msg+'').delay(3000).fadeOut('slow');
}否则{
window.location.href=重定向;
}
}否则{
$('#js contact result').fadeIn('slow').html(''+error_msg+'').delay(3000).fadeOut('slow');
}
$(“#js contact btn”).attr(“disabled”,false);
}
});
如果有人能给我指出一些我可以学到更多的资源,或者能帮助我解决问题,我会非常感激。谢谢大家!

var dataString = $(form).serialize();
不允许上载文件

而是使用formdata javascript对象

var dataString = new FormData(form);

不能将form.serialize()用于文件输入


检查此处:

这不是PHPMailer。你想用PHPMailer吗?@billy.farroll你说得对,我把标题删掉了。