«^»
4.5. Sending electronic mail

Here is a WWW page containing a WWW form to obtain the details of an e-mail message from a visitor to this WWW page:

0178: <HTML><BODY>
0179: <FORM METHOD="POST" ACTION="mail.php">
0180:    <P>
0181:    Enter the name of the sender:    <INPUT TYPE="Text" NAME="from">
0182:    <P>
0183:    Enter the name of the recipient: <INPUT TYPE="Text" NAME="to">
0184:    <P>
0185:    Enter the subject of the message:<INPUT TYPE="Text" NAME="subject">
0186:    <P>
0187:    Enter the text of the message:   <INPUT TYPE="Text" NAME="message">
0188:    <P>
0189:    Enter the name of the server:    <INPUT TYPE="Text" NAME="server">
0190:    <P>
0191:    <INPUT TYPE="Submit" VALUE="Send message">
0192: </FORM>
0193: </BODY></HTML>

And here is a PHP script to send an e-mail message:

0194: <HTML><BODY>
0195: <?php
0196:    $to      = $_POST["to"];
0197:    $subject = $_POST["subject"];
0198:    $message = $_POST["message"];
0199:    $from    = $_POST["from"];
0200:    $server  = $_POST["server"];
0201:    ini_set("SMTP", "$server");
0202:    $result = mail("$to", "$subject", "$message", "From: $from");
0203:    print "<CENTER>result is: $result.</CENTER>";
0204: ?>
0205: </BODY></HTML>

Go to the WWW form at: http://www.dur.ac.uk/barry.cornelius/papers/phpintro/code/mail.htm

Note: it is possible to configure PHP to disable any attempt to send e-mail.