View Full Version : How can I use webmail on when I use my computer as a webserver?

03-06-2005, 11:08 AM
I am running Win XP Professional and have been told that I should be able to use my computer as a webserver (which I know how to do) and also use Webmail (but I donít know how to do that). Therefore I wonder if anyone knows how to set up webmail (or can provide a useful link about the topic) so I can use a form on my webpage to send e-mails to my e-mail account with the ISP.

03-06-2005, 12:19 PM
If all you're doing is taking values from an email form and then emailing them to a certain email address, then it's easy. I managed it no problem and I'd never even heard of PHP 60 posts ago. Here's a simple example. Put the two files in the same directory, or alter the path in your form.


// Sets up the form to process the results using 'sendmail.php. Alter the path
// if 'sendmail.php' is in a different directory.

<form method="post" action="sendmail.php">

// Supplies a hidden value that will tell you what page the user came from.
// Not essential, only useful if you have more than one form like this.

<input type="hidden" name="page" value="Name of the page the form is on." class="textform"/>

// The actual form. Add extra inputs if you want more fields.

<td><input type="text" name="name" size="40" class="textform"/></td>
<td>Email Address</td>
<td><input type="text" name="email" size="40" class="textform"/></td>
<td><textarea name="notes" rows="10" cols="40" class="textform"></textarea></td>
<td align="right"><input type="reset" value="Clear"/></td>
<td><input type="submit" value="Send Info"/></td>


OK, so put that in your XHTML page, editing the style to match your page. It will send the values 'page' (which might not be necessary), 'name', 'email' and 'notes' to 'sendmail.php'. Adding more fields is easy enough, just put more inputs in with the relevant details.

Now the code for sendmail.php.


// Puts the user's email address in the variable $email.

$email = $_REQUEST['email'] ;

// Puts the message together. The bits in the "" are actual text, the other bits
// will insert the details from the form. \n is a line break.

$message = "Page:";
$message .= $_REQUEST['page'];
$message .= "\nName:";
$message .= $_REQUEST['name'];
$message .= "\nNotes:";
$message .= $_REQUEST['notes'];

// Sends the email to 'target@address.com' with a subject of 'Subject Of
// Email'. Inserts the message in the email. Says it's from the user's email
// address.

mail( "target@address.com", "Subject Of Email",
$message, "From: $email" );

// Redirects the user to www.yoursite/thanks.html.

header( "Location: http://www.yoursite/thanks.html" );

OK, so obviously you have to change a few things there to reflect your site and your email address.



function in PHP means 'add this to what's already there' so

$message .= $_REQUEST['notes'];

means 'add 'notes' to the end of $message'. So if you've added new fields to your form in the XHTML you need to add them here too. For example, if there was an input in your form named 'location', you'd need to alter the bit that generates the message in the PHP to this:

$message = "Page:";
$message .= $_REQUEST['page'];
$message .= "\nName:";
$message .= $_REQUEST['name'];
$message .= "\nNotes:";
$message .= $_REQUEST['notes'];
$message .="\nLocation:";
$message .= $_REQUEST['location'];

So say some one fills in the form like this:

Name Me
Email me@me.com
Notes Hello world!
Location Somewhere

this would send an email to the address you specify that looks like his:

Name : Me
Email : me@me.com
Notes : Hello world!
Location : Somewhere

Hope this helps. It's the second bit of PHP advice I've given out. Let me know if it works!