0

I am having a newsletter HTML email template found here. I want when the button is pressed, the page doesn't refresh and an info is sent to my DB; for example MYSQL.

I have found this question and it's answer. But there is a PHP file involved which I don't know what it should have. And as you will notice there is no form in the templates in the link provided.

I know that AJAX is part of my answer, but I don't know how to use it in such situation; where I don't have a form.

So, is there an answer to my question or is it just impossible to do such a thing?

Any help is so much appreciated.

Tes3awy
  • 2,166
  • 5
  • 29
  • 51
  • 4
    `just impossible to do such a thing`, nothing is impossible in web :D. Your Answer is `ajax`. On your linked questions is a good example to call a php file without reloading the page. `send_mail.php` is your target php file. – Sysix Aug 23 '17 at 19:54
  • @Sysix In the link I provided there is a `form`; yet the template I provided doesn't have a form. I am bit confused. I want anyone to enlighten and clarify things to me a bit. – Tes3awy Aug 23 '17 at 19:55
  • You can use AJAX for this type of thing. This is literally it's purpose. [Here's some info that will get you understanding AJAX](https://www.w3schools.com/xml/ajax_intro.asp) – Tom O. Aug 23 '17 at 19:57
  • show us your template. without it we can't help you – Sysix Aug 23 '17 at 19:58
  • @Sysix It's on the first line. The link – Tes3awy Aug 23 '17 at 19:59
  • that your email template. we need your input's for email and submittion – Sysix Aug 23 '17 at 20:00
  • @Sysix Let me explain more. This is a newsletter email where when sent the recipient let's say will press the `call to action`, let it be a like button for example. So when pressed I get the ID of the recipient and that he liked the newsletter mail. – Tes3awy Aug 23 '17 at 20:03
  • Do you have a web server set up? Just wondering what your back-end looks like. You mentioned MySQL; is that your DBMS? Are you using another language such as PHP, Java etc. to communicate with your database? – Tom O. Aug 23 '17 at 20:10
  • @TommyO Actually this is a good question. But I don't know from where to start the process of implementing what I asked about. Read the comment just above yours. You might get what I want. Provided that the page doesn't refresh. – Tes3awy Aug 23 '17 at 20:13
  • you must give the visitor on your webpage a form where they can register to your newsletter – Sysix Aug 23 '17 at 20:15
  • @Sysix I know what you say about registering and this is the easiest part and already implemented. What I want is the action from the client; that he liked the newsletter sent to him and his ID. – Tes3awy Aug 23 '17 at 20:17
  • send his ID or some other identifier within the action url. And then you can check via php and `$_GET` which user clicked the button – Sysix Aug 23 '17 at 21:10

1 Answers1

1

It is indeed possible to have a form tag in an email -- in your case your PHP would have to be an endpoint on a webserver that the form would submit to. However, doing so would open whatever the endpoint was (the form's action attribute) in the user's web browser. It sounds like you're thinking of forms in web pages that get intercepted with JavaScript to handle the form data (or do validation, or any number of other things) -- this isn't possible in an email since email clients generally don't run JavaScript (with a couple exceptions which run some limited form of JavaScript).

doesntgolf
  • 52
  • 2
  • 6
  • The email template is a newsletter email where when sent the recipient let's say will press the `call to action`, let it be a like button for example. So when pressed I get the ID of the recipient and that he liked the newsletter mail without refreshing the page. So does this explain more of what I am asking about? If not let me know. – Tes3awy Aug 23 '17 at 20:07
  • Yeah -- unfortunately that's not possible. The "without refreshing the page" is the problematic part. There are two ways I can think of that you could go: send a tracking image in the html for the email (although this method is easily evade-able, and only tracks opens, not quite what you're looking for), or have a regular link in the email and track the opens on that page. In either case you would probably include a unique querystring for the user, or have some other identifier in the link or image src you sent. – doesntgolf Aug 23 '17 at 20:32
  • So is there anything else rather than AJAX to use to do what I want "Without Refreshing The Page"? Or it's just not possible because mail clients block JavaScript? – Tes3awy Aug 27 '17 at 11:58
  • 1
    That's correct -- it's impossible because mail clients block Javascript (including AJAX). IMO your closest option is to set up a webpage that your "call to action" text in your email will link to. Then you can track opens on that webpage. You can also pass in the user identifier in a query string on the link, and track that on the webpage. – doesntgolf Aug 28 '17 at 15:27