01.
<?php
02.
03.
04.
$host
=
"smtp.host.com"
;
05.
$port
=
"587"
;
06.
$username
=
""
;
07.
$password
=
""
;
08.
09.
10.
$messageBody
=
""
;
11.
12.
if
(
$_POST
[
'name'
]!=
'false'
){
13.
$messageBody
.=
'<p>Visitor: '
.
$_POST
[
"name"
] .
'</p>'
.
"\n"
;
14.
$messageBody
.=
'<br>'
.
"\n"
;
15.
}
16.
if
(
$_POST
[
'email'
]!=
'false'
){
17.
$messageBody
.=
'<p>Email Address: '
.
$_POST
[
'email'
] .
'</p>'
.
"\n"
;
18.
$messageBody
.=
'<br>'
.
"\n"
;
19.
}
else
{
20.
$headers
=
''
;
21.
}
22.
if
(
$_POST
[
'state'
]!=
'false'
){
23.
$messageBody
.=
'<p>State: '
.
$_POST
[
'state'
] .
'</p>'
.
"\n"
;
24.
$messageBody
.=
'<br>'
.
"\n"
;
25.
}
26.
if
(
$_POST
[
'phone'
]!=
'false'
){
27.
$messageBody
.=
'<p>Phone Number: '
.
$_POST
[
'phone'
] .
'</p>'
.
"\n"
;
28.
$messageBody
.=
'<br>'
.
"\n"
;
29.
}
30.
if
(
$_POST
[
'fax'
]!=
'false'
){
31.
$messageBody
.=
'<p>Fax Number: '
.
$_POST
[
'fax'
] .
'</p>'
.
"\n"
;
32.
$messageBody
.=
'<br>'
.
"\n"
;
33.
}
34.
if
(
$_POST
[
'message'
]!=
'false'
){
35.
$messageBody
.=
'<p>Message: '
.
$_POST
[
'message'
] .
'</p>'
.
"\n"
;
36.
}
37.
38.
if
(
$_POST
[
"stripHTML"
] ==
'true'
){
39.
$messageBody
=
strip_tags
(
$messageBody
);
40.
}
41.
42.
if
(
$host
==
""
or
$username
==
""
or
$password
==
""
){
43.
$owner_email
=
$_POST
[
"owner_email"
];
44.
$headers
=
'From:'
.
$_POST
[
"email"
] .
"\r\n"
.
'Content-Type: text/plain; charset=UTF-8'
.
"\r\n"
;
45.
$subject
=
'A message from your site visitor '
.
$_POST
[
"name"
];
46.
47.
try{
48.
if
(!mail(
$owner_email
,
$subject
,
$messageBody
,
$headers
)){
49.
throw
new
Exception(
'mail failed'
);
50.
}
else
{
51.
echo
'mail sent'
;
52.
}
53.
}catch(Exception
$e
){
54.
echo
$e
->getMessage() .
"\n"
;
55.
}
56.
}
else
{
57.
require_once
'Mail.php'
;
58.
59.
$to
=
$_POST
[
"owner_email"
];
60.
$subject
=
'A message from your site visitor '
.
$_POST
[
"name"
];
61.
$headers
=
array
(
62.
'From'
=>
'From:'
.
$_POST
[
"email"
] .
"\r\n"
.
'Content-Type: text/plain; charset=UTF-8'
.
"\r\n"
,
63.
'To'
=>
$to
,
64.
'Subject'
=>
$subject
);
65.
66.
$smtp
= Mail::factory(
67.
'smtp'
,
68.
array
(
69.
'host'
=>
$host
,
70.
'port'
=>
$port
,
71.
'auth'
=> true,
72.
'username'
=>
$username
,
73.
'password'
=>
$password
));
74.
75.
$mail
=
$smtp
->send(
$to
,
$headers
,
$messageBody
);
76.
77.
try{
78.
if
(PEAR::isError(
$mail
)){
79.
echo
$mail
->getMessage();
80.
}
else
{
81.
echo
'mail sent'
;
82.
}
83.
}catch(Exception
$mail
){
84.
echo
$mail
->getMessage() .
"\n"
;
85.
}
86.
}
87.
?>