RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-331559

Павел Рыбакин's questions

Martin Hope
Павел Рыбакин
Asked: 2022-08-26 21:02:43 +0000 UTC

使用 phpmailer 发送纯 javascript 表单

  • 0

有一个登陆页面,您需要使用纯javascript提交表单。信寄出去了,却空空如也。一切都适用于jquery。

const forms = document.querySelectorAll('form');
const message = {
    loading: 'img/form/spinner.svg',
    success: 'Спасибо! Скоро мы с вами свяжемся',
    failure: 'Что-то пошло не так...'
};

forms.forEach(item => {
    postData(item);
});

function postData(form) {
    form.addEventListener('submit', (e) => {
        e.preventDefault();

        let statusMessage = document.createElement('img');
        statusMessage.src = message.loading;
        statusMessage.style.cssText = `
            display: block;
            margin: 0 auto;
        `;
        form.insertAdjacentElement('afterend', statusMessage);
    
        const formData = new FormData(form);

        const object = {};
        formData.forEach(function(value, key){
            object[key] = value;
        });

        fetch('mailer/smart.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(object)
        }).then(data => {
            console.log(data);
            showThanksModal(message.success);
            statusMessage.remove();
        }).catch(() => {
            showThanksModal(message.failure);
        }).finally(() => {
            form.reset();
        });
    });
}

function showThanksModal(message) {
  const prevModalDialog = document.querySelector('.modal__dialog');

  prevModalDialog.classList.add('hide');
  openModal();

  const thanksModal = document.createElement('div');
  thanksModal.classList.add('modal__dialog');
  thanksModal.innerHTML = `
      <div class="modal__content">
          <div class="modal__close" data-close>×</div>
          <div class="modal__title">${message}</div>
      </div>
  `;
  document.querySelector('.modal').append(thanksModal);
  setTimeout(() => {
      thanksModal.remove();
      prevModalDialog.classList.add('show');
      prevModalDialog.classList.remove('hide');
      closeModal();
  }, 4000);

}

<?php 
header('Content-Type: application/json');


$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$textarea = $_POST['textarea'];

require_once('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = 'utf-8';

// $mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'mail@gmail.com';                 // Наш логин
$mail->Password = 'gmail';                           // Наш пароль от ящика
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to
 
$mail->setFrom('mail@gmail.com', 'Сайт');   // От кого письмо 
$mail->addAddress('mail@yandex.ru');     // Add a recipient
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Данные';
$mail->Body    = '
        Пользователь оставил данные <br> <br>
    Имя: ' . $name . ' <br><br>
    Номер телефона: ' . $phone . '<br><br>
    E-mail: ' . $email . '<br><br>
    Cообщение: ' .$textarea . '';

if(!$mail->send()) {
    return false;
} else {
    return true;
}

?>

结果

解决 方法 把这段代码写在php文件的开头

$_POST = json_decode( file_get_contents("php://input"), true );
javascript
  • 1 个回答
  • 10 Views
Martin Hope
Павел Рыбакин
Asked: 2022-07-05 21:37:46 +0000 UTC

帮助在 gulp 中嵌入 imagemin-webp

  • 0

无法将 alljpeg和png图片的转换嵌入到webp. 您需要确保所有图像都转换为文件夹dist,并且还创建了图像webp:

const gulp        = require('gulp');
const browserSync = require('browser-sync');
const sass        = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('gulp-autoprefixer');
const rename = require("gulp-rename");
const imagemin = require('gulp-imagemin');
const webp = require('imagemin-webp');
const htmlmin = require('gulp-htmlmin');
const extReplace = require("gulp-ext-replace");



gulp.task('server', function() {

    browserSync({
        server: {
            baseDir: "dist"
        }
    });

    gulp.watch("src/*.html").on('change', browserSync.reload);
});

gulp.task('styles', function() {
    return gulp.src("src/scss/**/*.+(scss|sass)")
        .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
        .pipe(rename({suffix: '.min', prefix: ''}))
        .pipe(autoprefixer())
        .pipe(cleanCSS({compatibility: 'ie8'}))
        .pipe(gulp.dest("dist/css"))
        .pipe(browserSync.stream());
});

gulp.task('watch', function() {
    gulp.watch("src/scss/**/*.+(scss|sass|css)", gulp.parallel('styles'));
    gulp.watch("src/*.html").on('change', gulp.parallel('html'));
    gulp.watch("src/js/**/*.js").on('change', gulp.parallel('scripts'));
    gulp.watch("src/fonts/**/*").on('all', gulp.parallel('fonts'));
    gulp.watch("src/icons/**/*").on('all', gulp.parallel('icons'));
    gulp.watch("src/img/**/*").on('all', gulp.parallel('images'));
});

gulp.task('html', function () {
    return gulp.src("src/*.html")
        .pipe(htmlmin({ collapseWhitespace: true }))
        .pipe(gulp.dest("dist/"));
});

gulp.task('scripts', function () {
    return gulp.src("src/js/**/*.js")
        .pipe(gulp.dest("dist/js"))
        .pipe(browserSync.stream());
});

gulp.task('fonts', function () {
    return gulp.src("src/fonts/**/*")
        .pipe(gulp.dest("dist/fonts"))
        .pipe(browserSync.stream());
});

gulp.task('icons', function () {
    return gulp.src("src/icons/**/*")
        .pipe(gulp.dest("dist/icons"))
        .pipe(browserSync.stream());
});

gulp.task('images', function () {
    return gulp.src("src/img/**/*")
        .pipe(imagemin())
        .pipe(gulp.dest("dist/img"))
        .pipe(browserSync.stream());
});

gulp.task('default', gulp.parallel('watch', 'server', 'styles', 'scripts', 'fonts', 'icons', 'html', 'images'));

gulp
  • 1 个回答
  • 10 Views
Martin Hope
Павел Рыбакин
Asked: 2020-04-06 23:32:20 +0000 UTC

重置按下的单选框和复选框。限制点击复选框的数量

  • 1

我正在用 javascript 创建一个训练测试,当 backstart () 函数重置按下的复选框和收音机时,我需要这样做。您还需要确保用户在一个问题中只能选中 5 个复选框中的 3 个。

var rez=0,
d=document;
function v3(){
  for(i=0; i<d.getElementsByName("q3").length; i++){

      if(d.getElementsByName("q3")[i].checked) {

        if(i==0){rez+=2;}
        if(i==2){rez+=2;}
        if(i==3){rez+=1;}
      }

  }
alert(rez);

}
<div id="v3" class="qdiv">
          <p class="quest">Для облика древнейшего человека характерны:</p><br>
          <label><input type="checkbox" name="q3" value="1" />выступающие челюсти</label><br><br>
          <label><input type="checkbox" name="q3" value="2" />прямая походка</label><br><br>
          <label><input type="checkbox" name="q3" value="3" />прыгающая походка</label><br><br>
          <label><input type="checkbox" name="q3" value="4" />руки, свисающие ниже колен</label><br><br>
          <a href="#" onclick="v3()" class="btnflip">
             ответить
          </a>
        </div>

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Павел Рыбакин
Asked: 2020-04-02 02:47:14 +0000 UTC

单击另一个嵌套列表时自动隐藏嵌套列表

  • 0

当点击一个列表项打开一个嵌套列表时有一个菜单,你需要让它在你点击另一个嵌套列表时,我们打开的最后一个嵌套列表自己关闭。假设我点击“原始采集者和猎人”,然后点击“原始农牧民”,然后“原始采集者和猎人”自动隐藏。另外,如何使列表在悬停时展开?

$(document).ready(function() {
  $("#menuCnt > ul > li > a").click(function() {
    $(this).find("~ ul").stop().slideToggle("slov");
  });
});
#menuCnt ul li {
  list-style: none;
  border-bottom: 1px solid #eaeaea;
  border-radius: 10px;
  }
  #menuCnt ul li a {
  display: block;
  text-decoration: none;
  color: #333;
  padding: 10px;
  border-radius: 10px;
}
#menuCnt > ul > li > ul {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="menuCnt">
 
  <ul>
    <li><a href="#" class="textbold">Первобытные собиратели и охотники</a>
      <ul>
        <li><a href="#">Древнейшие люди</a></li>
        <li><a href="#">Родовые общины охотников и собирателей</a></li>
        <li><a href="#"> Возникновение искусства и религиозных верований</a></li>
      </ul>
    </li>
    <li><a href="#" class="textbold">Первобытные земледельцы и скотоводы</a>
      <ul>
        <li><a href="#">Возникновение земледелия и скотоводства</a></li>
        <li><a href="#">Появление неравенства и знати</a></li>
      </ul>
    </li>
    <li>
      <a href="#"> Счет лет в истории</a>
    </li>
  </ul>
  </div>

jquery
  • 1 个回答
  • 10 Views
Martin Hope
Павел Рыбакин
Asked: 2020-03-30 02:35:03 +0000 UTC

如何将脚本从 ht 文档标签传输到 js 文件

  • 1

大家好,我在一个网站上找到了一个现成的预加载器,但是它都是嵌入在html中的,我决定把所有东西都放在单独的文件中,我设法把样式放到一个单独的css文件中,而javaScript不起作用。脚本中需要更改哪些内容才能使其在单独的包含的 js 文件中工作?

<style type="text/css">#hellopreloader>p{display:none;}#hellopreloader_preload{display: block;position: fixed;z-index: 99999;top: 0;left: 0;width: 100%;height: 100%;min-width: 1000px;background: #86E2D5 url(http://hello-site.ru//main/images/preloads/ball-triangle.svg) center center no-repeat;background-size:98px;}</style>
<div id="hellopreloader"><div id="hellopreloader_preload"></div><p><a href="http://hello-site.ru">Hello-Site.ru. Бесплатный конструктор сайтов.</a></p></div>
<script type="text/javascript">var hellopreloader = document.getElementById("hellopreloader_preload");function fadeOutnojquery(el){el.style.opacity = 1;var interhellopreloader = setInterval(function(){el.style.opacity = el.style.opacity - 0.05;if (el.style.opacity <=0.05){ clearInterval(interhellopreloader);hellopreloader.style.display = "none";}},16);}window.onload = function(){setTimeout(function(){fadeOutnojquery(hellopreloader);},1000);};</script>

var hellopreloader = document.getElementById("hellopreloader_preload");

function fadeOutnojquery(el) {
  el.style.opacity = 1;
  var interhellopreloader = setInterval(function() {
    el.style.opacity = el.style.opacity - 0.03;
    if (el.style.opacity <= 0.03) {
      clearInterval(interhellopreloader);
      hellopreloader.style.display = "none";
    }
  }, 16);
}
window.onload = function() {
  setTimeout(function() {
    fadeOutnojquery(hellopreloader);
  }, 300);
};

javascript
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5