This question already has an answer here:
Below is the code for the basic email function.script. It actually uses a form on a website to set the variables in the script above to send an email. But its not working perfectly, please help me to fix it!
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone@example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>
</div>
Try this - Add header in your code.
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone@example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = trim($_REQUEST['comment']);
$headers = 'From:' .$email. "
" .
'Reply-To: info@domain.com' . "
" .
'MIME-Version: 1.0' . "
" .
'Content-type: text/html; charset=iso- 8859-1' . "
" .
'X-Mailer: PHP/' . phpversion();
//send email
$result = mail($admin_email, $subject, $comment, $headers);
//Email response
if($result)
echo "Thank you for contacting us!";
else
echo "Something went wrong.";
}
Try this
mail($admin_email, $subject, $comment, "From:" . $email);
Which server/environment that you are running on?
If it's Linux/Ubuntu. It might because there is a missing library. Try to install it using the following command.
apt-get install sendmail
But some log/output would be nice. Does the program throw any error/exception?
Try it Like this:
//send email
mail($admin_email, $subject, $comment, "From:" . $email);
and if not sending mail again then you must debug your code step by step and check all values comes or not in variables.