Link to home
Start Free TrialLog in
Avatar of mistaking
mistaking

asked on

Sending e-mail from a web form?

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?
Avatar of duerra
duerra

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 =)
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
Avatar of mistaking

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Gartlag
Gartlag

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
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");
}
You have sendmail in Windows?
Hey Mistaking ....
Check out this website ... should give you some guidance :)

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

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



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