I have this form and I am trying to send the contents of the contact us form to this mail scientology2016@gmail.com but it is not sending any mail for some reason and I can't figure out the error in this.
<form method="post" action="process.php">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control input-lg" name="name" placeholder="UserName">
</div>
<div class="form-group">
<input type="text" class="form-control input-lg" name="email" placeholder="E-Mail">
</div>
<div class="form-group">
<input type="text" class="form-control input-lg" name="usertel" placeholder="phone">
</div>
</div>
<div class="col-md-6">
<textarea class="form-control input-lg" name="subject" placeholder="Your Message"></textarea>
<button type="button" class="btn btn-primary btn-lg btn-block">Contact Us </button>
</div>
</form>
and this is the php code for sending mail which I wrote but it doesn't work
<?php
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$subject2 = ($_GET['subject']) ?$_GET['subject'] : $_POST['subject'];
$tel = ($_GET['usertel']) ?$_GET['usertel'] : $_POST['usertel'];
$comment = ($_GET['body']) ?$_GET['body'] : $_POST['body'];
if ($_POST) $post=1;
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 (!$errors) {
$to = 'scientology2016@gmail.com';
$from = $name . ' <' . $email . '>';
$subject = 'Message from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Subject</td><td>' . $subject2 . '</td></tr>
<tr><td>TelPhone</td><td>' . $tel . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Message</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
$result = sendmail($to, $subject, $message, $from);
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
} else {
echo $result;
}
} else {
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo '<a href="form.php">Back</a>';
exit;
}
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
$headers .= 'From: ' . $from . "rn";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
could anyone please help me in this case.
Aucun commentaire:
Enregistrer un commentaire