i have a php mail function which sends out emails with content from the contact form.but when i send this email on my website. instead of the from header being the email address entered, it is username@srv30.000webhost.com and i don't know why. my php mail function is below.
$email is the email entered by the user.
EDIT: Subject: Comment from hello X-PHP-Script: kwp.host22.com/form_action.php for 78.147.187.64 Message-Id: <20131124204151.478EC28021@srv30.000webhost.com> Date: Sun, 24 Nov 2013 15:41:51 -0500 (EST) From: a5485011@srv30.000webhost.com Return-Path: a5485011@srv30.000webhost.com X-OriginalArrivalTime: 24 Nov 2013 20:41:52.0292 (UTC) FILETIME=[9B09B640:01CEE955]
full php script:
$name = ($_GET['Name']) ? $_GET['Name'] : $_POST['Name'];
$email = ($_GET['Email']) ?$_GET['Email'] : $_POST['Email'];
$phone = ($_GET['Phone']) ?$_GET['Phone'] : $_POST['Phone'];
$comment = ($_GET['Comment']) ?$_GET['Comment'] : $_POST['Comment'];
// flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
// Simple server side validation for POST data, of course, you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$comment) $errors[count($errors)] = 'Please enter your comment.';
// if the errors array is empty, send the mail
if (!$errors) {
// recipient
$to = '<example@example.com>';
// sender
$from = $name . ' <' . $email . '>';
// subject and the html message
$subject = 'Comment from ' . $name;
$message = '
<!DOCTYPE html>
<html>
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Phone</td><td>' . $phone . '</td></tr>
<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
// send the mail
$result = @mail($to, $subject, $message, $from);
// if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
// else if GET was used, return the boolean value so that
// ajax script can react accordingly
// 1 means success, 0 means failed
} else {
echo $result; }
// if the errors array has values
} else {
// display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo '<a href="contact.php">Back</a>';
exit;}
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
$headers .= 'Reply-To: ' .$email . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
@mail($to, $subject, $message, $headers);
if ($result) return 1;
else return 0;}
im quite new to PHP so any help would be apreciated. thankyou