Sending e-mail from a web form?

mistaking used Ask the Experts™
I have been developing a web site for my company to access from where ever they are for details of our clients, etc. What I would like to be able to do is to send e-mails to them via a page on our web site.
The site has been designed using entirely php and MySQL, and i believe these are the only things installed on the web server.

If i want each client to link to a web form from which i can e-mail them, how would i go about this?
Do i need to install an SMTP service on the server?
How hard is this and can i get one free?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

If you're using Windows, you'll need an SMTP server.  While it's not free, you can configure it for up to 30 days, and then those are  the settings that you're required to keep from then on.  It's a great mail server:
You can use it forever... but like I said, make sure you have your configuration how you want it before your 30 days are up, because then you have to keep them that way ;)

It's not hard to use, but it will take you a few minutes to figure out what's going on if you're not familiar with how email servers work.  I knew nothing about them when I got Merak, but now I'm farily comfortable with it.

As for the actual sending of the email and the form, I can help you with that, too - just ask.  Make a form with a textarea, and submit it.  On submission, do your typical variable checking, and then send it using the mail() function.  It's very easy =)

Hi mistaking....
If you are programming in Unix ... the function to use is mail()

mail("address@to.sendto", $Subject-Line, $Body_of_Text);

This is presuming that you have a senders email default set up in php

I'm not sure about windows, but I'd assume that as long as the default sender
is set up and that you can email from your machine ...  mail should work to ...

Set up your form and store the relevant information directly into the mail function/variables
It is as easy as that ;)
All the Best,


Ok apparently i have sendmail on the server, and i am programming on windows in php.
I have created a form  but how do i use sendmail to email the form contents?
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

If you ensure that in your php.ini file ... ( in the c:\winnt or c:\windows .. whatever )...

do a find for SMTP ... ensure u have the right server
under this you have sendmail_from ..... ensure you have your address ..

If this is ok ... when the user submits the form ... check that $submit was pressed ...

then store the values you wish to use in variables ...

i.e.....    $Send_To =   $Emailbox   (Name of InputBox)
             $Subject =    $Subjectbox_Name
             $Body =        $Textbox_Name." \n\n  \t\tplus all this extra stuff u need to say !!\n\n"

mail($Send_To, $Subject, $Body);

I hope this is what you were asking .. best of luck with it ...
Gearoid ;)

Just call the mail() command in PHP, here's the full documentation

If you have sendmail it should just work.  and you can add your variables in as arguments and you're there

good luck!

I would advice actually sending yourself a test email first ..
just to make sure it is working ...

if $submit
   mail("", "Testing Mail", "It works \n yours sincerely, \n me");

You have sendmail in Windows?

Hey Mistaking ....
Check out this website ... should give you some guidance :)


Create a form. Name the file emailform.php

<form action="sendmail.php" method="POST">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="subject">
<input type="text" name="name">
<textarea name="content" cols="51" rows="14" ></textarea>
<input type="submit" value="Send">

Create a php file name sendmail.php

$name= $_POST['name'];
$email= $_POST['email'];
$subject= $_POST['subject'];
$content = $_POST['content'];


$message = " 


" ;

mail($youremail, $subject, $message, "From: $email\nX-Mailer: PHP/" . phpversion());

//auto responder

$subject2 = "Email received";
$message2 = " 

Dear $name,

blar blar blar" ;

mail($email, $subject2, $message2, "From: yourname<>\nX-Mailer: PHP/" . phpversion());

header("Location: thankyou.php");


this should be what you want, enjoy.

Maybe this will help you... This is a "Contact Us" deal I use on my site.

The Form (form.php):


<title>Contact Us</title>


<font face=arial size=4><b>
BS-Linux Web Mail Form</b><font size=3>
Use the form below or&nbsp;
style=color:0C5A0C>e-mail us here</a>

<form action="submitform.php" method="post">
<table cols=2 rows=4 cellspacing=5>
Your Name: &nbsp;</b>
<input type="text" name="name" size=35 maxlength=50><br>
Your E-mail: &nbsp;</b>
<input type="text" name="email" size=35 maxlength=50><br>
Subject: &nbsp;</b>
<input type="text" name="subject" size=35 maxlength=50<br><br>
</td></tr><tr><td valign=top>
Message: &nbsp;</b>
<textarea name="body" cols="40" rows="10"></textarea>
<input type="hidden" name="ipaddress" value="<? $REMOTE_ADDR ?>">
<input type="submit" name="submit" value="Send Message">



And the php mail code (submitform.php)

<font face="arial" size=4><b>

//Thank user for submitting an inquiry
//Display info being submitted back to user

echo "<center>";
echo "Thank you for Contacting Us!";
echo "<br><font size=3></b>";
echo "The following message was sent:";
echo "<br><br>";

echo "Name:&nbsp;";
echo $name;
echo "<br>";

echo "E-mail:&nbsp;";
echo $email;
echo "<br>";

echo "Subject:&nbsp;";
echo $subject;
echo "<br><br>";

echo "Message Body:";
echo "<br>";
echo stripslashes($body);

/* Assemble the e-mail data */
/* recipients */
$recipient .= "Brian A. Stumm <>";

/* message */
$message .= stripslashes($body);
$message .= " \n";

/* Signature */
$message .= "--\r\n";
$message .= " \n";                  

/* headers */
$headers .= "From: $name <$email>\n";
$headers .= "Reply-To: $email\n";
$headers .= "X-Sender: $email\n";
$headers .= "X-Mailer: BS-Linux Automated Web Response\n";
$headers .= "Return-Path: $email\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";

/* Send form submission by e-mail */
mail($recipient, $subject, $message, $headers);


Perhaps that will give you a starting point, you'll need to edit it for your needs...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial