Jump to content
Muhammad_Bilal

E-mailing just only with javascript...

Recommended Posts

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......

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Of course you can use a single Php file to provide a mail service for these various HTML forms.

  • Like 1

Share this post


Link to post
Share on other sites

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.......

Share this post


Link to post
Share on other sites

No, those services don't exist because it can't be done. All mail services use a server-side language.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by Muhammad_Bilal

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...