基本上,表单已“提交”,但电子邮件从未到达,并且我的服务器日志中出现错误...无法弄清楚:/
这是我正在使用的代码
html表单
[ec2-user@xxx httpd]$ sudo service httpd status
httpd (pid 12079) is running...
这是form.php,我正在使用它打印到服务器日志
<form id="main-contact-form" name="contact-form">
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group mb-5">
<!-- Label -->
<label for="contactName">
Ime
</label>
<!-- Input -->
<input name="name" type="text" class="form-control" id="contactName" required>
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group mb-5">
<!-- Label -->
<label for="contactEmail">
Email
</label>
<!-- Input -->
<input name="email" type="email" class="form-control" id="contactEmail" required>
</div>
</div>
</div> <!-- / .row -->
<div class="row">
<div class="col-12">
<div class="form-group mb-7 mb-md-9">
<!-- Label -->
<label for="contactMessage">
Kako vam lahko pomagamo?
</label>
<!-- Input -->
<textarea name="message" class="form-control" id="contactMessage" rows="5" required></textarea>
</div>
<div class="g-recaptcha" data-sitekey="mypublickey" data-callback="onSubmit" data-theme="dark" data-size="invisible">
</div>
</div>
</div> <!-- / .row -->
<div class="row justify-content-center">
<div class="col-auto">
<!-- Submit -->
<button name="submit" class="btn btn-primary lift">
Pošlji
</button>
</div>
</div> <!-- / .row -->
</form>
?>
这是mailsend.js文件
<?php
$name;$email;$message;$captcha;
if(isset($_POST['name'])){
$name=$_POST['name'];
}if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['message'])){
$message=$_POST['message'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
$filename ='contact_log.txt';
$text =$name."\t".$email."\t".$message."\t";
file_put_contents($filename, $text, FILE_APPEND);
if(!$captcha){
file_put_contents($filename,"FAILURE\n", FILE_APPEND);
throw new Exception("Captcha is empty", 1);
}
$secretKey = "mysecretkey";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
file_put_contents($filename,"FAILURE\n", FILE_APPEND);
throw new Exception("Captcha validation failed", 1);
} else {
$name = @trim(stripslashes($name));
$from = @trim(stripslashes($email));
$subject = @trim(stripslashes("contact"));
$message = @trim(stripslashes($message));
$to = 'myemail@domain.com';
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
$mail_status = mail($to, $subject, $message, implode("\r\n", $headers));
if($mail_status){
file_put_contents($filename,"SUCCESS\n", FILE_APPEND);
}else{
file_put_contents($filename,"FAILURE\n", FILE_APPEND);
throw new Exception("Error sending mail", 1);
}
}
任何帮助将不胜感激,因为我已经为此努力了2天,但没有成功。