Tutorials Books Videos Forums

-- online Change the theme! Search!
Rambo ftw!

Customize Theme


Color

Background


Done

PHP Mail Form

by j. edick. aka jubba   | filed under Flash and ActionScript

This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.

Well a lot of people keep asking about PHP mail forms. I don't have Flash on this computer, so I'm just going to have to make everyone stick with a regular HTML form. I will give the code and then explain that code.

Create a new PHP file and copy and paste the following code:

  <?
//------------------------------------------------
// File: 'phpmail.php'
// Func: using mail();
//------------------------------------------------

$Subject = "Test E-mail";
$toEmail = "[email protected]";

if(submit)
{
mail($fromEmail, $Subject, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">");
}
?>

<html>
<head>
<title>Mail Tutorial</title>
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="<? echo($PHP_SELF) ?>">
Your E-mail:

<input type="text" name="fromEmail" size="25">

Your Name: <input type="text" name="fromName" size="25">

Your Message:

<textarea cols="50" rows="5" name="nMessage">Your Message Here...

 

Now to break apart the PHP code:

                    $Subject = "Test
  E-mail";

  $toEmail = "[email protected]";

These are variables for your e-mails subject and your target recipient's e-mail. This is generally where you put your e-mail address if you are the one that is going to be receiving the e-mail

if(submit)
{

  mail($fromEmail, $Subject, $nMessage."\nFrom:
  ".$fromName."<".$fromEmail.">");
}

This is an if statement that checks to see if the submit button has been pressed. If yes, then it executes the script inside the brackets.
The mail() function on the inside is what sends the e-mail to you.

The mail function works like this:
mail ( string to, string subject, string message).

For any help, please post on the forums.

Cheers,
Jubs

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums.

Your support keeps this site going! 😇

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright KIRUPA 2026 //--