_Send E-mail_
This is a very simple script that will send an e-mail using the standard mail () function. Designed for beginners. I was going to upload it but it didn't work so here's the code.
AI
KI-Zusammenfassung: 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.
Quellcode
<code><font color="#000000">
<font color="#0000BB"><?php
<br /></font><font color="#FF8000">// See comments below (right above the form).
<br />
<br /> </font><font color="#007700">if (</font><font color="#0000BB">$mode </font><font color="#007700">== </font><font color="#DD0000">"submit"</font><font color="#007700">) {
<br /> if (</font><font color="#0000BB">$enable_html </font><font color="#007700">!= </font><font color="#DD0000">"on"</font><font color="#007700">) {
<br /></font><font color="#FF8000">/*
<br /> The user does not want to send the e-mail in HTML format, so we must get
<br /> rid of the HTML in the message.
<br />*/
<br /> </font><font color="#0000BB">$mail_body </font><font color="#007700">= </font><font color="#0000BB">htmlspecialchars </font><font color="#007700">(</font><font color="#0000BB">$mail_body</font><font color="#007700">);
<br /> }
<br />
<br /></font><font color="#FF8000">// Now we set the headers for our e-mail message.
<br />
<br /> </font><font color="#0000BB">$headers </font><font color="#007700">.= </font><font color="#DD0000">"MIME-Version: 1.0 \n"</font><font color="#007700">;
<br /> </font><font color="#0000BB">$headers </font><font color="#007700">.= </font><font color="#DD0000">"Content-type: text/html; charset=iso-8859-1 \n"</font><font color="#007700">;
<br /> </font><font color="#0000BB">$headers </font><font color="#007700">.= </font><font color="#DD0000">"from:$mail_from\r\nCc:$mail_cc\r\nBcc:$mail_bcc"</font><font color="#007700">;
<br />
<br /></font><font color="#FF8000">/*
<br /> Now it's time to send the message, we'll use the mail () function.
<br /> The function will return TRUE on success, FALSE on failure.
<br /> We can use that to make sure the e-mail was sent without
<br /> any problems.
<br /> The "@" in front of the function is optional. In PHP, whenever
<br /> there is an @ in front of ANY function, the script will not show
<br /> any errors. As we will let the user know if anything goes wrong
<br /> ourselves, we don't need PHP to give the errors for us and we can
<br /> show the error however we want (not with Warning: ... on line ...).
<br />*/
<br />
<br /> </font><font color="#007700">if (@</font><font color="#0000BB">mail </font><font color="#007700">(</font><font color="#0000BB">$mail_to</font><font color="#007700">, </font><font color="#0000BB">$mail_subject</font><font color="#007700">, </font><font color="#0000BB">$mail_body</font><font color="#007700">, </font><font color="#0000BB">$headers</font><font color="#007700">)) {
<br /> print (</font><font color="#DD0000">"<h1><font color=\"#004000\">The e-mail was sent successfully!</font></h1>"</font><font color="#007700">);
<br /> } else {
<br /> print (</font><font color="#DD0000">"<h1><font color=\"#880000\">An error occurred while sending the e-mail!</font></h1>"</font><font color="#007700">);
<br /> }
<br />
<br /></font><font color="#FF8000">// We don't need to show the form again.
<br />
<br /> </font><font color="#007700">exit;
<br /> }
<br /></font><font color="#0000BB">?>
<br /></font>
<br /><html>
<br />
<br /><head>
<br /><title>Send e-mail</title>
<br /><script language="javascript">
<br /> function DoSubmit ()
<br /> {
<br />/*
<br /> This javascript will check if the important fields have been filled in.
<br /> The control is pretty basic (if the user types " " it will see it as full,
<br /> but it is enough to alert a person who forgot to fill out a form, without
<br /> him / her having to wait until the form refreshes (good for slow modems).
<br />
<br /> The return ""; command will exit the function, so that the form is only
<br /> submitted when it is valid.
<br />*/
<br />
<br /> if (document.form.mail_from.value == "") {
<br /> alert ("You forgot to enter the 'from' field.");
<br /> document.form.mail_from.focus ();
<br /> return "";
<br /> }
<br />
<br /> if (document.form.mail_to.value == "") {
<br /> alert ("You forgot to enter the 'to' field.");
<br /> document.form.mail_to.focus ();
<br /> return "";
<br /> }
<br />
<br /> if (document.form.mail_subject.value == "") {
<br /> alert ("You forgot to enter the 'subject' field.");
<br /> document.form.mail_subject.focus ();
<br /> return "";
<br /> }
<br />
<br /> if (document.form.mail_body.value == "") {
<br /> alert ("You forgot to enter the 'body' field.");
<br /> document.form.mail_body.focus ();
<br /> return "";
<br /> }
<br />
<br /> document.form.submit ();
<br /> }
<br /></script>
<br /></head>
<br />
<br /><body>
<br /><!--
<br /> By setting the form's action to $PHP_SELF, this code will work even
<br /> when you change the name from email.php into whatever you want (.php).
<br />
<br /> The included (hidden) field, mode, will be used to see if the user has
<br /> submitted the form or if the page is loading for the first time. If the
<br /> user has submitted the page, the variable $mode will have the string
<br /> "submit" as its value, otherwise the variable will be empty.
<br />-->
<br /><form action="<font color="#0000BB"><?php </font><font color="#007700">print (</font><font color="#0000BB">$PHP_SELF</font><font color="#007700">); </font><font color="#0000BB">?></font>" method="post" name="form">
<br /> <table>
<br /> <tr>
<br /> <td>From:</td>
<br /> <td><input type="text" name="mail_from" size="40"></td>
<br /> </tr>
<br /> <tr>
<br /> <td>To:</td>
<br /> <td><input type="text" name="mail_to" size="40"></td>
<br /> </tr>
<br /> <tr>
<br /> <td>Cc:</td>
<br /> <td><input type="text" name="mail_cc" size="40"></td>
<br /> </tr>
<br /> <tr>
<br /> <td>Bcc:</td>
<br /> <td><input type="text" name="mail_bcc" size="40"></td>
<br /> </tr>
<br /> <tr>
<br /> <td>Subject:</td>
<br /> <td><input type="text" name="mail_subject" size="40"></td>
<br /> </tr>
<br /> <tr>
<br /> <td valign="top">Body:</td>
<br /> <td><textarea name="mail_body" cols="40" rows="10"></textarea></td>
<br /> </tr>
<br /> <tr>
<br /> <td></td>
<br /> <td><input type="checkbox" name="enable_html"> enable HTML in this message.</td>
<br /> </tr>
<br /> <tr>
<br /> <td><input type="hidden" name="mode" value="submit"></td>
<br /> <td><input type="button" onclick="DoSubmit ()" value="Send e-mail"></td>
<br /> </tr>
<br /> </table>
<br /></form>
<br />
<br /></body>
<br />
<br /></html></font>
</code>
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine