• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with Form to email

New Here ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

I have a template that I have been modifying. I am not experienced but need help. what do i need to edit to get it to submit to my email?

This is the js script for the form.

// Contact Form Submition
function checkRequire(formId, targetResp) {
targetResp.html('');
var email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
var url = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
var image = /\.(jpe?g|gif|png|PNG|JPE?G)$/;
var mobile = /^[\s()+-]*([0-9][\s()+-]*){6,20}$/;
var facebook = /^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]/;
var twitter = /^(https?:\/\/)?(www\.)?twitter.com\/[a-zA-Z0-9(\.\?)?]/;
var google_plus = /^(https?:\/\/)?(www\.)?plus.google.com\/[a-zA-Z0-9(\.\?)?]/;
var check = 0;
$('#er_msg').remove();
var target = (typeof formId == 'object') ? $(formId) : $('#' + formId);
target.find('input , textarea , select').each(function() {
if ($(this).hasClass('require')) {
if ($(this).val().trim() == '') {
check = 1;
$(this).focus();
targetResp.html('You missed out some fields.');
$(this).addClass('error');
return false;
} else {
$(this).removeClass('error');
}
}
if ($(this).val().trim() != '') {
var valid = $(this).attr('data-valid');
if (typeof valid != 'undefined') {
if (!eval(valid).test($(this).val().trim())) {
$(this).addClass('error');
$(this).focus();
check = 1;
targetResp.html($(this).attr('data-error'));
return false;
} else {
$(this).removeClass('error');
}
}
}
});
return check;
}
$(".submitForm").on("click", function() {
var _this = $(this);
var targetForm = _this.closest('form');
var errroTarget = targetForm.find('.response');
var check = checkRequire(targetForm, errroTarget);
if (check == 0) {
var formDetail = new FormData(targetForm[0]);
formDetail.append('form_type', _this.attr('form-type'));
$.ajax({
method: 'post',
url: 'ajax.php',
data: formDetail,
cache: false,
contentType: false,
processData: false
}).done(function(resp) {
if (resp == 1) {
targetForm.find('input').val('');
targetForm.find('textarea').val('');
errroTarget.html('<p style="color:green;">Mail has been sent successfully.</p>');
} else {
errroTarget.html('<p style="color:red;">Something went wrong please try again latter.</p>');
}
});
}
});

 


});

})(jQuery);


This is the html for it

<!--pst form wrapper start -->
<div class="single_contact_form_wrapper pst_toppadder50 pst_bottompadder0">
<div class="container">
<div class="row">
<div class="pst_form_control">

<div class="pst_single_forms"><input type="text" placeholder="Name" /><i class="fa fa-user"></i></div>
</div>
<div class="pst_form_control pst_form_control_2">
<div class="pst_single_forms"><input type="email" placeholder="Email" /><i class="fa fa-envelope"></i></div>
</div>
<div class="pst_form_control">
<div class="pst_single_forms"><input type="text" placeholder="Zip Code" /><i class="fa fa-star"></i></div>
</div>
<div class="pst_form_control">
<div class="pst_single_forms pst_form_control_2"><input type="text" placeholder="Phone" /><i class="fa fa-phone"></i></div>
</div>
<div class="pst_btn_form">
<ul>
<li>
<a href="#" class="tem-btn">
<div class="btn-front">submit</div>
<div class="btn-back">submit</div>
</a>
</li>
</ul>
</div>
<div class="sp_choose_heading_main_wrapper pst_bottompadder0">
<p><span><strong>Submit your interest and recieve discounts on your first cleaning!!</strong></span></p>
</div>
</div>
</div>
</div>
<div>&nbsp;</div>
<!--pst form wrapper end-->

Views

229

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

In your previous post (https://community.adobe.com/t5/dreamweaver/need-code-for-making-my-form-submit-to-email/m-p/11736059...), I gave you a link on how to email a form.

 

If you follow that, you will see that the code that you have supplied will do nothing. The jQuery script refers to a form which you do not have in the HTML and sends the form to be actioned to a file called ajax.php, the contents of which you have not shown here.

 

Please follow the instructions in my link in your previous post.

 

As a side note: This post is seen as a duplicate post and should by rights be deleted. I have not deleted it because I feel for you. In future, it is best to stay with the same topice untill it has been answered to your satisfaction.

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Ben,

 

Thank you for your help, and I didnt realize about the repeat post I'm sorry.  I reviewed your link but I was trying to keep my site as is since it was a template.  I do however have the ajax.php, shown below.   It has an email from and to in it which I can change but I want to make sure it works.  currently if I click submit it just returns to the index page.

 

Thanks for any help.  

 

<?php
if(isset($_POST) && !empty($_POST)){
$full_name = (isset($_POST['full_name']))?$_POST['full_name']:'';
$first_name = (isset($_POST['first_name']))?$_POST['first_name']:'';
$middle_name = (isset($_POST['middle_name']))?$_POST['middle_name']:'';
$last_name = (isset($_POST['last_name']))?$_POST['last_name']:'';
$email = (isset($_POST['email']))?$_POST['email']:'';
$subject = (isset($_POST['subject']))?$_POST['subject']:'';
$message = (isset($_POST['message']))?$_POST['message']:'';
$contact_no = (isset($_POST['contact_no']))?$_POST['contact_no']:'';
$date = (isset($_POST['date']))?$_POST['date']:'';
$time = (isset($_POST['time']))?$_POST['time']:'';

if($full_name == ''){
$full_name = $first_name.' '.$middle_name.' '.$last_name;
}

$sendMessage = $mailSubject = '';
if($_POST['form_type'] == 'contact'){
$mailSubject = 'Contact Details';
$sendMessage = "<p>Hello,</p><p>".$full_name." has sent a message having </p><p><b>Phone No:</b> ".$contact_no."</p><p><b>Email id:</b> ".$email."</p><p><b>Subject:</b> ".$subject."</p><p><b>Query is:</b> ".$message."</p>";
}elseif($_POST['form_type'] == 'inquiry'){
$mailSubject = 'Inquiry Details';
$sendMessage = "<p>Hello,</p><p>".$full_name." has sent a message having </p><p><b>Email id:</b> ".$email."</p><p><b>Phone:</b> ".$contact_no."</p><p><b>Subject:</b> ".$subject."</p><p><b>Date :</b> ".$date."</p><p><b>Time :</b> ".$time."</p><p><b>Message :</b> ".$message."</p>";
}

if($sendMessage != ''){
$fromEmail = 'support@webstrot.com';
$toEmail = 'akshay@webstrot.com';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <$fromEmail>" . "\r\n";

if(mail($toEmail , $mailSubject , $sendMessage , $headers )){
echo 1;
}else{
echo 0;
}
}else{
echo 0;
}
}else{
echo 0;
}

?>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Am I missing an form action?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

On closer inspection, the code that you have shown should work. The only problem is most likely that you are trying the form out on a locl system that does not have a mail srever.

 

If you upload the files to a remote server that does have a PHPMailer facility, all should be well.

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2021 Jan 13, 2021

Copy link to clipboard

Copied

LATEST

1. Did you run a test from your remote server?

Be sure to upload all relevant scripts and forms to your permanent hosting server to test it.

 

2. Check your inbox's spam and junk folders for messages.

 

3. Failing that, contact your web host and ask them which form-to-email scripts they recommend you use with your hosting plan.

 

4. Or use a 3rd party form service like Wufoo.com, JotForms or MailChimp.

 

Nancy O'Shea— Product User, Community Expert & Moderator

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines