Sending e-mail from a web form?

mistaking
mistaking used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

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

Commented:
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:
http://www.merakmailserver.com/
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 =)

Commented:
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.e. admin@you.com

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,
Gearoid

Author

Commented:
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.

Commented:
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 .. admin@blah.com

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

http://uk.php.net/manual/en/function.mail.php

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

good luck!

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

if $submit
{
   mail("me@blah.com", "Testing Mail", "It works \n yours sincerely, \n me");
}

Commented:
You have sendmail in Windows?

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

http://www.potentialcreations.com/articles/win_mail.php

Gearoid

Commented:
Create a form. Name the file emailform.php

email.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
-------------------------------------------------------------

<?
ob_start();
$name= $_POST['name'];
$email= $_POST['email'];
$subject= $_POST['subject'];
$content = $_POST['content'];



$youremail="youremail@yourdomain.com";


$message = " 

$content

" ;

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<youremail@yourdomain.com>\nX-Mailer: PHP/" . phpversion());

header("Location: thankyou.php");

?>

this should be what you want, enjoy.



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

The Form (form.php):

<html>  

<head>
<title>Contact Us</title>
</head>            

<body>

<center>          
<font face=arial size=4><b>
<br>
BS-Linux Web Mail Form</b><font size=3>
<br>                
Use the form below or&nbsp;
<a href=mailto:me@mydomain.com
style=color:0C5A0C>e-mail us here</a>
<br><br>

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

<br><br><br><br><br>      

</body>
</html>            



And the php mail code (submitform.php)

<html>
<body>
<font face="arial" size=4><b>
<br>
<?

//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 <me@mydomain.com>";


/* 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