Muhammad_Bilal Posted September 22, 2014 Share Posted September 22, 2014 Salam or Hello @ All, It's me Bilal since a very long ago, today I'm posting this topic because I'm dive into a problem which is: I want to send a email after collecting data from html form which is pretty simple with the help of PHP but can the same functionality can be performed by using just JavaScript only? if so please discuss the possibilities on this topic. Don't be tell about the mailto function of the html because it is not good at all. I'm waiting for your pretty responses...... Link to comment Share on other sites More sharing options...
Ingolme Posted September 22, 2014 Share Posted September 22, 2014 Javascript cannot send e-mails. HTML can use mailto to request the browser to open a mailing client, but if you want anything more than that you'll certainly need a server-side language, such as PHP. Link to comment Share on other sites More sharing options...
davej Posted September 23, 2014 Share Posted September 23, 2014 Of course you can use a single Php file to provide a mail service for these various HTML forms. 1 Link to comment Share on other sites More sharing options...
Muhammad_Bilal Posted September 23, 2014 Author Share Posted September 23, 2014 Thanks, for both of you, Now i'm be concluded that sending e-mails is not possible with the javascript only some server-site language or other application is required, Correct? But have you know any of these services through which I can send eMails without using server-site? Have you know any service which can send email to gmail account using the client-side only? If so, please share with me. thanks again....... Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2014 Share Posted September 23, 2014 No, those services don't exist because it can't be done. All mail services use a server-side language. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 23, 2014 Share Posted September 23, 2014 The problem is that Javascript does not have a way to communicate with a mail server. You can use ajax to send a request to a different port (although you'll need to change your browser's default security settings to allow cross-domain and cross-port requests), but it's going to be an HTTP request, not an IMAP or SMTP request. The bottom line is that Javascript alone cannot contact a mail server. The best you can do is use Javascript to send a request to a web server, which then contacts the mail server. Link to comment Share on other sites More sharing options...
davej Posted September 23, 2014 Share Posted September 23, 2014 I don't know of any such services but they may exist. You might have to create your own. Each form would have one of more hidden fields (magic numbers) that would validate the post and also identify the desired email destination. The service code would need to be smart enough to ignore floods from hackers. Â --EDIT-- Â Apparently I am overlooking the limitations of cross-domain access. Link to comment Share on other sites More sharing options...
Muhammad_Bilal Posted September 25, 2014 Author Share Posted September 25, 2014 (edited) Saying Thanks once again to all, Both of you clear that some server-site is must be required to sending requests to a mail server and then collecting information from them. As justsomeguy said "The best you can do is use Javascript to send a request to a web server, which then contacts the mail server." I'm be asked that how to build such a system, basic algorithm something like this: Â Â JavaScript collect the data from the HTML form when, submit button is clicked. and showing message to the user something like: Data is sending.... Then Send this data using AJAX to the hosting server which then send the mail to the mail server . After sending the mail hosting server reply back to the requesting site and tell the status of the mail i.e. send or not. Then user message will change with the status of the mail i.e. Data has been sent if successful and An error if mail has not been sent. The URL of the page doesn't change during whole process. Â Please suggest how to write code for this. I'm a beginner JavaScript user so it is very difficult for me to writing the xml requests or code like this. Your help is appreciated...... Edited September 25, 2014 by Muhammad_Bilal Link to comment Share on other sites More sharing options...
thescientist Posted September 25, 2014 Share Posted September 25, 2014 you can just use a form instead, there are tutorials for this on the w3schools site http://www.w3schools.com/php/php_mail.asp Link to comment Share on other sites More sharing options...
Safeer008 Posted September 25, 2014 Share Posted September 25, 2014 (edited) You can send, but it will need some HTML tricks like window.open('mailto:test@example.com?subject=subject&body=body'); or See here. Edited September 25, 2014 by thescientist no advertising Link to comment Share on other sites More sharing options...
thescientist Posted September 25, 2014 Share Posted September 25, 2014 I wouldn't recommend that way, personally. It's not that hard to setup basic email sending with an HTML form and a little server side scripting. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 25, 2014 Share Posted September 25, 2014 After sending the mail hosting server reply back to the requesting site and tell the status of the mail i.e. send or not.Then user message will change with the status of the mail i.e. Data has been sent if successful and An error if mail has not been sent.You have the correct process, but the server will not be able to tell if the mail was actually sent. It can verify that the mail made it to the mail server, but it cannot verify that the mail was actually delivered to the destination account. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now