How to send emails in Javascript with ASP/PHP, seamlessly and without page refreshes or changes!
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.
AI
ملخص الذكاء الاصطناعي: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
كود المصدر
<p><font face="Arial" color="#800080" size="5">How to send emails in JavaScript
using ASP/PHP</font></p>
<p><font face="Arial">Have you ever wanted to send emails directly in
Javascript?<br>
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+ !!!</font></p>
<p><font face="Arial" size="3">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.<br>
If you want any information added or you have any questions, post feedback.</font></p>
<p><font face="Arial"><b>To allow sending emails you must have ASP or PHP
enabled on your server, also your server must allow to send emails.<br>
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.</b></font></p>
<p><font face="Arial">And now, how Javascript can send mails?<br>
Well, really, client side Javascript doesn't has features to send mails, that's
why ASP and/or PHP is used.<br>
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:</font></p>
<p><font size="2" face="Verdana" color="#000080"><script
language="JavaScript" id="sendemail" src></script><br>
<script><br>
document.scripts.sendemail.src="sendemail.php?address=user@email.com&message=Hello&subject=Hello+User!";<br>
</scirpt></font></p>
<p><font face="Arial">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.</font></p>
<p><font face="Arial">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:</font></p>
<p><font size="2" face="Verdana" color="#000080"><script
language="JavaScript" src="sendemail.js"></script></font></p>
<p><font face="Arial">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.</font></p>
<p><font face="Arial"><b>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.</b></font></p>
<p><font face="Arial">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</font></p>
<p><font size="2" face="Verdana" color="#000080"><script
language="JavaScript" src="sendemail.js"></script></font></p>
<p><b><font face="Arial">line in your web page.</font></b></p>
<p><font size="2" face="Verdana" color="#000080">//First create the Mail()
object and set in on a variable<br>
var easymail=new Mail();</font></p>
<p><font size="2" face="Verdana" color="#000080">//Set the server type, so the
script can know which page to call, the asp or php, if you are using a PHP
server<br>
//replace the "ASP_SERVER" with "PHP_SERVER", by default the
server is set to PHP_SERVER</font></p>
<p><font size="2" face="Verdana" color="#000080">//NOTE: If you choose
ASP_SERVER you must have CDONTS component installed<br>
//in your server in order to send the emails</font><br>
<font size="2" face="Verdana" color="#000080">easymail.ServerType=ASP_SERVER;</font></p>
<p><font size="2" face="Verdana" color="#000080">//Now set the address to which
the email will be sended<br>
easymail.To="username@email.com";<br>
//Add the CC address<br>
easymail.Cc="username2@email.com";<br>
//Add the BCC address<br>
easymail.Bcc="username3@email.com";</font></p>
<p><font size="2" face="Verdana" color="#000080">//Now set the address of the
one that sends the email<br>
easymail.ReplyTo="me@email.com";</font></p>
<p><font size="2" face="Verdana" color="#000080">//Now set the subject of the
email<br>
easymail.Subject="Here goes the subject of the email";</font></p>
<p><font size="2" face="Verdana" color="#000080">//Set the message of the email<br>
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";</font></p>
<p><font size="2" face="Verdana" color="#000080">//Send the email<br>
easymail.Send();</font></p>
<p><font face="Arial" size="3">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:<br>
1. EmailSenderAccessed - If it is set to true then the ASP/PHP email page was
loaded<br>
2. EmailSended - If it is set to true then the email was sended correctly</font></p>
<p><font face="Arial" size="3">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.</font></p>
<p><font size="2" face="Verdana" color="#000080">function CheckEmail(){<br>
//Show the message in the status bar<br>
window.status="Sending email...";<br>
//Check if the ASP/PHP email page was already loaded<br>
if(EmailSenderAccessed){<br>
//Now check if the email was sended or not and show the message<br>
if(EmailSended) window.alert("The email was sended succesully!");<br>
else window.alert("The email could not be sended");<br>
</font>}<font size="2" face="Verdana" color="#000080"><br>
//If ASP/PHP email page is not loaded yet, then check it again in 0.5 seconds
(500 milliseconds</font>)<font size="2" face="Verdana" color="#000080"><br>
else{<br>
setTimeout("CheckEmail();", 500);<br>
}<br>
}</font></p>
<p><font size="2" face="Verdana" color="#000080">//Send the email<br>
easymail.Send();<br>
//Now call the function what will alert user when email was sended<br>
CheckEmail();</font></p>
<p><b><font face="Arial" size="3">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
:)</font></b></p>
التعليقات الأصلية (3)
مسترجع من Wayback Machine