简体   繁体   中英

Contact Us form not Functioning HTML5/PHP Help needed

Good day,

Newbie here in PHP. I have been working on a website (free template) and got all the functions to work except the Contact Us part of the code. I don't get any errors it just does not send any email to the listed email or send back a response to the sender.

Here is the HTML Side of the code:

<form id="contact-form" action="php/mail.php">
<div class="control-group">
<div class="controls">
<input class="span6" type="text" id="name" name="name" placeholder="* Your name..."/>
<div class="error center" id="err-name">Please enter your name.</div>
</div></div>
<div class="control-group">
<div class="controls">
<input class="span6" type="email" name="email" id="email" placeholder="* Your email..."/>
<div class="error center" id="err-email">Please enter a valid email adress.</div></div></div>
<div class="control-group">
<div class="controls">
<textarea class="span6" name="comment" id="comment" placeholder="* Comments..."></textarea>
<div class="error center" id="err-comment">Please enter your comment.</div>
</div></div>
<div class="control-group">
<div class="controls">
<button id="send-mail" class="message-btn">Send message</button>
</div></div></form>

and this is the mail.php code used:

include 'functions.php';

if (!empty($_POST)) {

$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);

//your email adress
$emailTo = "myemail@gmail.com"; //"myemail@gmail.com";

//from email adress
$emailFrom = "myemail@gmail.com"; //"myemail@gmail.com";

//email subject
$emailSubject = "Mail from MyEmail";

$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if ($name == "")
$data['success'] = false;

if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;

if ($comment == "")
$data['success'] = false;

if ($data['success'] == true) {

$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);

$data['success'] = true;
echo json_encode($data);
}
}

I am really stuck at this point and this is the only issue I have left hope someone can help point out what I am doing wrong.

Regards,

Rafael

为了使form发送POST请求,您需要通过添加method属性来指定它:

<form id="contact-form" action="php/mail.php" method="post">

Is your php mail script placed in the cgi directory? This is my mail script:

       <?php $name = trim(strip_tags($_POST['name']));
   $email = trim(strip_tags($_POST['email']));
   $message = htmlentities($_POST['message']);
   $subject = "Some subject";
   $to = 'info@xxx.de';
   $body = <<<HTML 
$message 
HTML;

   $headers = "From: $email\r\n";
   $headers .= "Content-type: text/html\r\n";

   // send the email
   mail($to, $subject, $body, $headers);

   // redirect afterwords, if needed
   header('Location: ../contact/thx.html');?>

And it is placed in cgi directory.

After much research and help from CodeGoodie I think the blame lies with the Hosting. I had asked how I could check Server logs to detect the error and they just replied I need to upgrade to be able to use that feature (although it is supposed to be part of the feature already). Thanks for all the help guys. I did learn a lot :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM