大佬教程收集整理的这篇文章主要介绍了带附件的文件不发送,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在表单上使用 ReCaptcha 3。 当我尝试发送带有附件的邮件时,会发送邮件但不发送附件。 但是带附件的邮件可以不用reCaptcha部分发送。
我一直在寻找几个希望解决这个问题的线程,但很困惑。
HTML 表单
<HTML lang="en">
<head>
<Meta http-equiv="Content-Type" content="text/HTML; charset=utf-8">
<title>Mail</title>
</head>
<body>
<form method="post" ID="contact-form" enctype="multipart/form-data" action="testmailer.php">
<input name="fname" placeholder="Your name" title="Your name" type="text" /></div>
SELEct one or more files:
<input name="userfile[]" type="file" multiple="multiple">
<input type="hIDden" name="recaptcha_response" ID="recaptchaResponse">
<input type="submit" ID="submit-button" value="Send files">
</form>
<div ID="alertm"></div>
<script src="https://cdnjs.cloudFlare.com/AJAX/libs/jquery/3.5.1/jquery.min.Js"></script>
<script async src="https://www.Google.com/recaptcha/API.Js?render=******site key******"></script>
<script>
$('#contact_form').submit(function() {
event.preventDefault();
$('#alertm').text('Processing...').fadeIn(0);
grecaptcha.ready(function() {
grecaptcha.execute('**site key**',{action: 'contact'}).then(function(token) {
$('#contact_form').prepend('<input type="hIDden" name="g-recaptcha-response" value="' + token + '">');
$.post("form.php",{name: name,token: token},function(result) {
console.log(result);
if(result.success) {
alert('Thanks for posTing comment.')
} else {
alert('You are spAMMer ! Get the @$%K out.')
}
});
});
});
});
</script>
</body>
</HTML>
表单邮件
<?php
require $_SERVER['document_ROOT'] . '/phpR_39_11845@ailer/src/phpR_39_11845@ailer.php';
use phpR_39_11845@ailer\phpR_39_11845@ailer\phpR_39_11845@ailer;
$mail = new phpR_39_11845@ailer();
$msg = '';
if(isset($_POST['fname'])){
$name=$_POST['fname'];
}
if (array_key_exists('userfile',$_fileS)) {
$email_to = "toemail@domain.com";
$mail->setFrom('fromemail@somedomain.com','From name');
$mail->addAddress($email_to);
$mail->Subject = 'Mail Subject';
$body = "name - $name\n";
$mail->Body = $body;
$mail->IsHTML(true);
echo $body;
for ($ct = 0; $ct < count($_fileS['userfile']['tmp_name']); $ct++)
{
$uploadfile = tempnam(sys_get_temp_dir(),sha1($_fileS['userfile']['name'][$ct]));
$filename = $_fileS['userfile']['name'][$ct];
if (move_uploaded_file($_fileS['userfile']['tmp_name'][$ct],$uploadfilE)) {
if (!$mail->addAttachment($uploadfile,$fileName)) {
$msg .= 'Failed to attach file ' . $filename;
}
} else {
$body .= 'Failed to move file to ' . $uploadfile;
}
}
}
$error_output = '';
$success_output = '';
$recaptcha_url = 'https://www.Google.com/recaptcha/API/siteverify';
$recaptcha_secret = '******secret key******';
$recaptcha_response = $_POST['recaptcha_response'];
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_responsE);
$recaptcha = Json_decode($recaptcha);
if ($recaptcha->success == true && $recaptcha->score >= 0.5 && $recaptcha->action == 'contact') {
if (!$mail->send()) {
echo 'Mail Sent';
$msg .= 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$msg .= 'message sent!';
}
$success_output = "Your message sent successfully";
} else {
$error_output = "Something went wrong. Please try again later";
echo $msg;
}
$output = array(
'error' => $error_output,'success' => $success_output
);
echo Json_encode($output);
?>
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的带附件的文件不发送全部内容,希望文章能够帮你解决带附件的文件不发送所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。