Hi all, Im new to sitepoint and hope I will be able to contribute as well as learn.
Apologies if this topics has been posted elsewhere.
I have a contact form which uses php to send email.
Once the form has been validated it sends the email, but the email body is empty as well as the 'email from' field, the email subject is the only data that gets posted to my inbox, nothing else, im fairly new to php so any help with my code would be welcome.
<?php
// get posted data into local variables
$name = Trim(stripslashes($POST['txtname']));
$title = Trim(stripslashes($POST['txttitle']));
$company = Trim(stripslashes($POST['txtcompany']));
$from = Trim(stripslashes($POST['txtemail']));
$to = 'test@test.test';
$telephone = Trim(stripslashes($POST['txtphone']));
$subject = Trim(stripslashes($POST['txtsubject']));
$message = Trim(stripslashes($POST['txtmessage']));
$date = date("m/d/Y H:i:s");
$IP = $SERVER['REMOTE_ADDR'];
// prepare email body text
$body = '
<html>
<head>
<title>myTitle</title>
</head>
<body>
<table width="99%">
<tr>
<td>Name :</td>
<td>$name</td>
</tr>
<tr>
<td>Title :</td>
<td>$title</td>
</tr>
<tr>
<td>Company name :</td>
<td>$company</td>
</tr>
<tr>
<td>From :</td>
<td>$from</td>
</tr>
<tr>
<td>Contact number :</td>
<td>$telephone</td>
</tr>
<tr>
<td>Subject :</td>
<td>$subject</td>
</tr>
<tr>
<td>Message :</td>
<td>$message</td>
</tr>
<tr>
<td colspan="2">$date || $IP</td>
</tr>
</table>
</body>
</html>
';
// send email
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1\r\n';
$headers .= 'From: <$from>';
$success = mail($to, $subject, $body, 'From: <$from>', $headers);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=success.htm">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm">";
}
?>