PHP Mailing system

PHP Add comments

I have decided to write a tutorial on creating a mailing system In PHP. I do this because I have recently had to build one for a client and I found it quite interesting as I had not used the mail function in ages.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?
// Enter your email
$to = "andrew@pryde-design.co.uk";
 
// Contact form
$form = '<form name="Email Form" method="post" action="'.htmlentities($_SERVER['PHP_SELF']).'">Name<br />';
$form .= '<input type="text" name="name" /><br /><br />Subject<br />';
$form .= '<input type="text" name="subject" /><br /><br />Message<br />';
$form .= '<textarea name="msg" cols="50" rows="5"></textarea><br />';
$form .= '<input type="submit" name="Submit" value="Submit" /></form>';
 
// asks if the form been filled in
if (!empty($_POST['name']) && !empty($_POST['subject']) && !empty($_POST['msg']))
{
//if it has send the data
if (mail($to,$_POST['subject'],$_POST['msg']))
{
print "Message Sent!";
}
else
{
print "There was an error please contact " . $to . " via your mail cleint";
}
}
else
{
print $form;
}
?>

The code should explain all but if not comment and I will get back to you.

Andrew

Leave a Reply

WP Theme & Icons by Pryde Design
Entries RSS Comments RSS Log in