/**
* PHP Email Form Validation - v3.9
* URL: https://bootstrapmade.com/php-email-form/
* Author: BootstrapMade.com
*/(function(){"use strict";let forms = document.querySelectorAll('.php-email-form');
forms.forEach(function(e){
e.addEventListener('submit',function(event){
event.preventDefault();let thisForm =this;let action = thisForm.getAttribute('action');let recaptcha = thisForm.getAttribute('data-recaptcha-site-key');if(! action ){
displayError(thisForm,'The form action property is not set!');return;}
thisForm.querySelector('.loading').classList.add('d-block');
thisForm.querySelector('.error-message').classList.remove('d-block');
thisForm.querySelector('.sent-message').classList.remove('d-block');const formData =newFormData(thisForm);if( recaptcha ){if(typeof grecaptcha !=="undefined"){
grecaptcha.ready(function(){try{
grecaptcha.execute(recaptcha,{action:'php_email_form_submit'}).then(token =>{
formData.set('recaptcha-response', token);
php_email_form_submit(thisForm, action, formData);})}catch(error){
displayError(thisForm, error);}});}else{
displayError(thisForm,'The reCaptcha javascript API url is not loaded!')}}else{
php_email_form_submit(thisForm, action, formData);}});});function php_email_form_submit(thisForm, action, formData){
console.log("thisForm:",thisForm)
console.log("action:",action)
console.log("formData:",formData)
fetch(action,{
method:'POST',
body: formData,
headers:{'X-Requested-With':'XMLHttpRequest'}}).then(response =>{
console.log(response)if( response.ok ){return response;}else{
console.log(response)thrownewError(`${response.status} ${response.statusText} ${response.url}`);}}).then(data =>{
console.log(data)
thisForm.querySelector('.loading').classList.remove('d-block');if(data.ok){
thisForm.querySelector('.sent-message').classList.add('d-block');
thisForm.reset();}else{
console.log(data)thrownewError(data ? data :'Form submission failed and no error message returned from: '+ action);}}).catch((error)=>{
displayError(thisForm, error);});}function displayError(thisForm, error){
thisForm.querySelector('.loading').classList.remove('d-block');
thisForm.querySelector('.error-message').innerHTML ="there is an error here";
thisForm.querySelector('.error-message').classList.add('d-block');}})();
وهذا كود ملف validate.js
<?php
/**
* Requires the "PHP Email Form" library
* The "PHP Email Form" library is available only in the pro version of the template
* The library should be uploaded to: vendor/php-email-form/php-email-form.php
* For more info and help: https://bootstrapmade.com/php-email-form/
*/// Replace contact@example.com with your real receiving email address
$receiving_email_address ='adham111mahfoud@gmail.com';if(file_exists($php_email_form ='../assets/vendor/php-email-form/php-email-form.php')){
include($php_email_form);}else{die('Unable to load the "PHP Email Form" Library!');}
$contact =new PHP_Email_Form;
$contact->ajax =true;
$contact->to = $receiving_email_address;
$contact->from_name = $_POST['name'];
$contact->from_email = $_POST['email'];
$contact->subject = $_POST['subject'];// استخدام حقل subject الجديد// Uncomment below code if you want to use SMTP to send emails. You need to enter your correct SMTP credentials/*
$contact->smtp = array(
'host' => 'example.com',
'username' => 'example',
'password' => 'pass',
'port' => '587'
);
*/
$contact->add_message($_POST['name'],'From');
$contact->add_message($_POST['email'],'Email');
$contact->add_message($_POST['phone'],'Phone',10);// إضافة حقل الهاتف
$contact->add_message($_POST['subject'],'Service',10);// إضافة حقل الخدمة
$contact->add_message($_POST['message'],'Message',10);// إضافة حقل الرسالة// إرسال البريد الإلكتروني
$response = $contact->send();// إعادة التوجيه إلى الصفحة السابقةif(isset($_SERVER['HTTP_REFERER'])){
header('Location: '. $_SERVER['HTTP_REFERER']);}else{// إعادة توجيه إلى صفحة افتراضية أو رسالة خطأ
header('Location: default-page.php');}exit();?>
السؤال
Adham Mahfoud
السلام عليكم
أنا استخدم مكتبة php email form وعندما أحاول عمل submit يعطيني هذا الخطأ
POST https://localhost/myProject/forms/contact.php 409 (Conflict)
هذا كود الفورم
وهذا كود ملف validate.js
وهذا كود ملف contac.php
ما هو الخطأ؟
10 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.