Creating an email form in PHP

From Nitix Knowledgebase

Jump to: navigation, search


 

Problem

How can I create an email form so that someone can email me from my website ?

 

Solution

Nitix has PHP built into its web system, which is a web scripting language. One can use PHP in conjunction with HTML forms to create a web page that will allow your customers to email you.

The following is a very simple email form that you start from:

<?PHP

/* Script to send an email to the given address from a form */

if ($command == "sendemail") 
{
// This is where the email will be sent
$email_to = "emails@gohere.com";

// This is the page the user will be shown once their email has been sent
$thank_you_page = "thankyou.php";

mail($email_to, $subject, $body, "From: $from");
header("Location: $thank_you_page");
}
?>
<html>
<head><title>Email form</title></head>
<body>
<form action="<?=$PHP_SELF?>" method="POST" name="email_form">
<input type="hidden" name="command" value="sendemail">
From: <input type="text" name="from">
Subject: <input type="text" name="subject">
Body: <textarea name="body"></textarea>
<input type="submit" value="Send Email">
</form>
</body>
</html>

Was this article helpful?

Retrieved from "http://kb.nitix.com/1769"
Account Info
Was this article helpful?
How can we improve
this article?
Have more detailed feedback?
Email: