我遇到了一個問題,我的PHP郵件代碼每天晚上運行像下午11:30。我確定沒有人點擊表單提交按鈕。電子郵件內容爲空。PHP郵件腳本每晚自動運行同一時間
在我的PHP郵件代碼中,我將這些內容添加到數據庫中,以防郵件不通過,然後發送郵件。
感謝
表:
<form action="background/mail.php" method="POST">
<div class="row">
<div class="six columns">
<label>Your email</label>
<input class="u-full-width" type="email" placeholder="[email protected]" name="email">
</div>
<div class="six columns">
<label>Reason for contacting</label>
<select class="u-full-width" name="reason">
<option>Inquiry</option>
<option>Order</option>
<option>Other</option>
</select>
</div>
</div>
<div class="row">
<div class="u-full-width">
<label>Message</label>
<textarea class="u-full-width" placeholder="Enter message here" name="message"></textarea>
<input class="button-primary" type="submit" value="Submit">
</div>
</div>
</form>
mail.php:
<?php
$to = "[email protected]";
$reason = "CUSTOMER MAIL: " . $_POST['reason'];
$email = $_post['email'];
$msg = $_POST['message'] . "\nemail: " . $email;
$header = "MIME-Version: 1.0\r\n";
$header.= "Content-type: text/html\r\n";
$header.= "From: " . $email . "\r\n";
$header.= "Reply-to: [email protected]\r\n" . "X-Mailer: PHP/" . phpversion();
require("login.php");
$sql = "INSERT INTO emails (email, message, reason) VALUES ('$email','$msg','$reason')";
if($conn->query($sql) === TRUE){
mail($to,$reason,$msg, $header);
echo "Added to database, mail sent.";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
你有沒有建立一個cron或東西嗎? –
如果您沒有設置任何cron作業來運行腳本,那麼嘗試添加capcha可能? –
您是否設置了cron作業?你如何確信當時沒有人提交你的表格? – Nick