You are Here: FAQ ->Scripting and Programming Languages->PHP mail explained->Article #2


WebHosting 5.0 This article is for 1&1 Linux WebHosting only.


How do I setup PHP Mail?



1. First you need to create a form to use the PHPmail script. A form will look something like the one below.
It must be saved as an HTM or HTML file. You can edit the one below to suit your own needs.

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contact Us</title>
<link rel="stylesheet" type="text/css" href="../../css/nms.css" />
</head>
<body>
<form method="post" action="mail.php">
  <table>
   <tr>
    <td>What is your name ?</td>
    <td><input type="text" name="name" /></td>
   </tr>
   <tr>
    <td>What is your e-mail address ?</td>
    <td><input type="text" name="email" /></td>
   </tr>
    <tr>
    <td> Comments:</td>
    <td><textarea name="data" cols=40 rows=6></textarea></td>
    </tr>
   <tr>
    <td colspan="2"><input type="submit" /></td>
   </tr>
  </table>
</form>
</body>
</html>
 


2. Next you need to create a file named mail.php which will contain the following code.

 
<?
$to = 'me@mydomain.com';
$subject = 'subject';
$message = 'From: ' . $_REQUEST['name'] . "\n\n" . $_REQUEST['data'];
$email = $_REQUEST['email'];
$headers = 'From: ' . $email . "\r\n" .
            'Reply-To: ' . $email . "\r\n" .
          'X-Mailer: PHP/' . phpversion();
 
mail ($to, $subject, $message, $headers);
header("Location: thanks.html");
?>
 

Note: You will replace 'me@mydomain.com' with your e-mail account and 'subject' with what
will be in the subject field of the e-mail. Replace "thanks.html" with the name of the page that the
viewer will be redirected to after submitting the form.


3. Upload both files into your webspace. Make sure to set the correct permission for the PHP file.
How do I upload a file?
How do I change file permissions?


Disclaimer: 1&1 provides the scripts and related information on this page as a courtesy, subject to 1&1's General Terms and Conditions of Service (the "GT&C"). As set forth in more detail in the GT&C, the scripts and information are provided "as-is", without any warranty, and 1&1 is not liable for any damages resulting from your use of the scripts or information.



Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not useful at all):
1 2 3 4 5