Quick Search for:  in language:    
tutorial,will,teach,make,your,Javascript,base
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Java/ Javascript Stats

 Code: 220,465. lines
 Jobs: 89. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for Java/ Javascript.
Gobang
By Geniusbob Xu Qiang on 11/27


Click here to see a screenshot of this code!Salary
By Vikram Ivatury on 11/25

(Screen Shot)

Click here to see a screenshot of this code!A (part10) Powerful Swing Code to Maintain CD Database
By James Smith K on 11/25

(Screen Shot)

String Calculator
By MadokaCoder on 11/24


Chobi Dekha
By ShuvoRim on 11/23


Click here to see a screenshot of this code!A basic Client Server application II
By Ronald Holland on 11/23

(Screen Shot)

Bookmark image
By darren kurn on 11/22


myFT
By Owolabi Oyapero on 11/22


Click here to see a screenshot of this code!Simple Socket example
By Steven McElrea on 11/20

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

How to send emails in Javascript with ASP/PHP, seamlessly and without page refreshes or changes!

Print
Email
 

Submitted on: 3/15/2003 7:46:52 PM
By: Design7 Software 
Level: Advanced
User Rating: By 3 Users
Compatibility:JavaScript

Users have accessed this article 5579 times.
 

(About the author)
 
     This tutorial will teach you how to make your own Javascript based email sender, it uses ASP/PHP to send the emails in a seamless way and without any page refreshes or changes. Note: Javascript doesn't sends the emails by itself, it uses ASP/PHP to send them, the advantage is that they are sended seamlessly and in realtime, plus you program the emails directly in Javascript. Please vote and leave your comments.

This article has accompanying files
 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

How to send emails in JavaScript using ASP/PHP

Have you ever wanted to send emails directly in Javascript?
This tutorial will teach you how to send emails in Javascript in a seamless way and also to be compatible with Internet Explorer  4+ and Netscape 4+ !!!

You will find attached a ZIP file the HTML page of this tutorial, the sendemail .js, .asp, and .php files, and also an email sender demo where you can find all the source code to make a simple email sender based on Javascript and ASP/PHP.
If you want any information added or you have any questions, post feedback.

To allow sending emails you must have ASP or PHP enabled on your server, also your server must allow to send emails.
If you only have ASP on your server check if it has a mail sending component named CDONTS, which is the most used by IIS servers, contact your webserver admin to check that feature.

And now, how Javascript can send mails?
Well, really, client side Javascript doesn't has features to send mails, that's why ASP and/or PHP is used.
What javascript does is to call a ASP/PHP page, then send some parameters to that pages, and then that pages will send the emails, and now, to make the email process fast and seamless, the ASP/PHP will be loaded as if they were a javascript file, for example look at this code:

<script language="JavaScript" id="sendemail" src></script>
<script>
document.scripts.sendemail.src="sendemail.php?address=user@email.com&message=Hello&subject=Hello+User!";
</scirpt>

What does this code does is to call a PHP send email page and pass some parameters to it, as if it was a javascript file, then the PHP page sends the email, and returns some javascript content like "var EmailSended=true;", so you can know the email was sended.

Now, this email send interface may sound quite complex or nonpractical to implement, that's way the code is already made so you can send emails with ease, first, you will have to download the ZIP file attached and copy the 3 files in there (sendemail.js, sendemail.asp, and sendemail.php) to your web server, then include this line of code on the pages where you will be sending emails:

<script language="JavaScript" src="sendemail.js"></script>

Now, to send emails you only need to make some easy code like this, the code was made so it as easy to use as possible and full of features like including mail subject, message, reply-to address, and CC/BCC addresses.

Note: Seamless email sending is only enabled on Internet Explorer version 4 or greater, on other browsers like Netscape, Opera, Mozilla, etc, a small popup will open the ASP/PHP page, and then closed after a few seconds.

Now here are is the code to send a mail with all these features, don't forget to include the 3 "sendemail" js, php, and asp files in your server, and also to include the

<script language="JavaScript" src="sendemail.js"></script>

line in your web page.

//First create the Mail() object and set in on a variable
var easymail=new Mail();

//Set the server type, so the script can know which page to call, the asp or php, if you are using a PHP server
//replace the "ASP_SERVER" wit // h "PHP_SERVER", by default the // server is set to PHP_SERVER

//NOTE: If you choose ASP_SERVER you must have CDONTS component installed
//in your server in order to send the em // ails
easymail.ServerType=ASP_SERVER;

//Now set the address to which the email will be sended
easymail.To="username@email.com";
//Add the CC address
easymail.Cc="username2@email.com";
//Add the BCC address
easymail.Bcc="username3@email.com";

//Now set the address of the one that sends the email
easymail.ReplyTo="me@email.com";

//Now set the subject of the email
easymail.Subject="Here goes the subject of the email";

//Set the message of the email
easymail.Message="Here is the content of the email message, if you want to split text into lines so it can be readable, you can use the '\r\n' characters, or better";

//Send the email
easymail.Send();

Now, if you want to know if the ASP/PHP was already loaded and/or if you want to know if the email was sended correctly, you can use some special variables which are:
1. EmailSenderAccessed - If it is set to true then the ASP/PHP email page was loaded
2. EmailSended - If it is set to true then the email was sended correctly

I have included some code so you can know if the email page was loaded and if the email was sended correctly, add the following code to the previous one.

function CheckEmail(){
//Show the message in the status bar
// window.status="Sending email...";
//Check if the ASP/PHP email page was al // ready loaded
if(EmailSenderAccessed){
//Now check if the email was sended or n // ot and show the message
if(EmailSended) window.alert("The email was sended succesully!");
else window.alert("The email could not be sended");
}
//If ASP/PHP email page is not loaded ye // t, then check it again in 0.5 seconds (500 milliseconds
)
else{
setTimeout("CheckEmail();", 500);
}

 }

//Send the email
easymail.Send();
//Now call the function what will alert // user when email was sended
CheckEmail();

Is as easy as it looks, if you liked this tutorial please vote and/or post your comments/feedback of it, it would be great :)

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.

Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:
1)Re-scan downloaded files using your personal virus checker before using it.
2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.


Other 8 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
4/17/2003 3:31:55 AM:
very nifty, i like it :)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/17/2003 10:02:03 AM:
Very cool!! Thanks from Italy
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Java/ Javascript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.