By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – Can jquery detect that an e-mail was sent from client’s mail?
JavaScript

Javascript – Can jquery detect that an e-mail was sent from client’s mail?

Admin
Last updated: 2023/12/11 at 3:53 PM
Admin
Share
5 Min Read
Can jquery detect that an e-mail was sent from client's mail?

Problem:

The goal is: my website’s user completes a set of fields (not a form), then hits “send e-mail” (some fields are verified for completeness), then the user’s e-mail platform is activated through “mailTo”, the e-mail is pre-populated and all the user has to do is send it. Here is the problem: Is there any way to detect that the user actually sent the e-mail? Right now, after the e-mail is supposedly sent, a little div pops up asking the user if the e-mail was sent, which is fine by me, but, I think, not solid enough. I do not want to use any external, type of “mail sender” app, or .ajax, due to spam issues, want to keep the communication as simple as possible, and, knowing that there is no complete way to verify an e-mail, prefer to leave it up to the user. This is why I also require a phone number to verify their booking (it is a hotel’s reservation website). Here is my code:

Contents
Problem:Solution:
$("#btnDone").click(function(){
    
    //variables, for verification purposes (check input of "input type: hidden" fields - not in a form):
    var ctxx = "", ce = $("#yce").val().length, ct = $("#yct").val().length, cnl = $("#cnc").val().length;
    
    //verification functions return error = 1, if error:
    if(ce > 0){isEmail();} //contains basic regex
    else{isPhone();} //one or the other is required
    if(error==0){iscnp();} if(error==0){isyn();} if(error==0){if(ct > 0){iscnt();}}
        
        //if verifications OK:
    if(error==0){
            
            //variables to be included in e-mail:
            ynx = $("#yn").val(), cex = $("#yce").val(), ctx = $("#yct").val(), cnx = $("#cnt").val(),
            npx =   $("#cnp").val(), ncx = $("#cnc").val();
            
            //structuring, before populating e-mail variables:
            if(cnl > 0){npx = npx + ", " + ncx}
        ctxx = "Phone: " + ctx + " " + "(" + cnx + ")"; temp = "E-mail: " + cex;
                if(ce==0){temp = ctxx;}else{if(ct > 0){temp = temp + " - " + " " + ctxx;}}
                
                //e-mail variables:
        var esubject = encodeURIComponent("Subject: Reservation at (hotel name)");
            var ebody = encodeURIComponent("Number of persons: " + npx
                    + "\n\n" + iv + " - " + ov + "\n" + stay  + " " + noni + " total" + "\n" 
                + "Reservation Name: " + ynx + "\n" + temp + "\n\n" 
            + "Thank you, we will contact you shortly to confirm your booking..." + "\n" 
            + "Please add any notes and special requests below:" + "\n\n\n\n\n");
                //send e-mail:
        window.location.href = "mailto:myemail@mail.com?subject=" + esubject + "&body=" + ebody;
        //asking the user if the e-mail was sent:
        $("#text1").text("Did you send your reservation e-mail?"); $("#text2").text("");
    }
});

The issue is with that last line. Instead of asking the user if the e-mail was sent, can jquery detect if it was? In other words, if the user hit “send” on his mail platform? Or, if that e-mail message actually reached my server? If not (probably the case), how can the above be done with PHP?

Solution:

No, you can’t detect this client-side (directly), with jQuery or anything else.

You can detect this server-side, by putting a unique identifier in the email (for instance, in the subject) and having your client-side code call your server-side code to check whether the email has been received by your mail server. (You may have to poll [or use a web socket or server-sent events, etc.], it’ll usually take at least a second or two, sometimes longer.) How you do it is almost entirely dependent on the details of your server environment (and would be too broad a question).

Alternatively, you can send the information to your server directly from your script instead of involving the user’s email system, as ADyson pointed out. That would be a fairly standard way to do it. If you need to validate their email address, send them an email with a code in it they then quote back (via clicking a link or replying to the email).

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article How do I dynamically enable/ disable a button based on the value inside a textbox Javascript – How do I dynamically enable/ disable a button based on the value inside a textbox
Next Article How to style LineStrings which are part of a GeometryCollection Javascript – How to style LineStrings which are part of a GeometryCollection
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?