JavaScript Sending an automated email sending automated emails,sending automated emails outlook,sending automated emails

I would like to have an automated email sent to a person's email when they press a button. I'm having a few problems, one I am not sure what the JavaScript for this would be. Two, I don't know how to mix both PHP and JavaScript, since I need to use PHP to get their email address and password from an SQL Table, and as far as I know, I need JavaScript to send the email. Finally, I am not sure how to add the password from the PHP into the email. Help on any of these would be greatly appreciated. Thanks.

Answer:1

You can send an email through PHP, but most of the answers on SO saying "use the mail() function" are outdated I presume and, in any case, do not work.

I would advise you to use JavaScript or simply an HTML form collecting a user ID or user email. Then pass that on as a parameter to your post function that calls the PHP you want to run.

In the PHP file, you read the email (for example, via $_POST['email']). Then you run a SQL query to retrieve the password WHERE the email is equal to the one you just read.

Finally, since you now have the password stored in a variable, you continue in your PHP file and use PHPMailer's function, as shown in examples like the following: https://github.com/PHPMailer/PHPMailer/blob/master/examples/mail.phps. Alternatively, you could use a similar library to achieve the same functionality.

Then you put the password in your email text and send it to the user.

However, a note of caution: it would be very unwise in terms of security to send passwords in plain text format (not encrypted) to a user's email address. I would advise you to send them an email with a password reset link instead, which would direct them to a form where they could select a new password and confirm it. That would require a different PHP file, where you would execute an UPDATE query to change the password that is stored in the database.

I assume you have already solved your problem, since this is an old question, but maybe this will help someone else who stumbles upon it.

Answer:2

I have done something similar to this in the past and the best way to do this is to create a HTML form. Then use php to get all of the data and still use that php to send the email. No javascript required. I can recommend these links

w3schools form email

Why do you need to access the data from the SQL table? Is this a password recovery type of form? If so, that can also be done with php. However, given that this is a Q&A help site and not a forum, I would hire a developer.

This link can help with accessing a mysql database from php.

This link can help with sending php email.

This link can help with sending html based email from php.

Answer:3

You may want to investigate AJAX via jQuery.

http://learn.jquery.com/ajax/

AJAX allows you to open a PHP script within javascript, and then do things with whatever the php script echos back.

If you do not mind navigating away from the interface page, an HTML form would work.

Answer:4

I know I could use variations of this answer to find out how many different types of data there are in an array: How to count the number of certain element in an array? But, what I am looking for ...

I know I could use variations of this answer to find out how many different types of data there are in an array: How to count the number of certain element in an array? But, what I am looking for ...

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following: WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: ...

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following: WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: ...

  1. websocket with handshake
  2. websocket handshake in c
  3. websocket handshake for ssl
  4. websocket bad handshake with resp

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

I've got some code that sends an ajax request when a form is being submitted. This works the first time the form is submitted (it's a search module), but only once. I've added an effect to highlight ...

I've got some code that sends an ajax request when a form is being submitted. This works the first time the form is submitted (it's a search module), but only once. I've added an effect to highlight ...

  1. response from ajax call
  2. response from ajax
  3. response from ajax post
  4. return response from ajax call
  5. get response from ajax
  6. get response from ajax call jquery
  7. get response from ajax post
  8. get response from ajax call
  9. get response from ajax jquery
  10. download response from ajax
  11. get response from ajax request
  12. get response from ajax javascript
  13. return response from ajax
  14. ajax call without response
  15. get response from ajax call javascript
  16. no response from ajax jquery
  17. alert response from ajax
  18. response.redirect from ajax call
  19. json response from ajax call
  20. return response from ajax success