私の連絡先フォームで非常に奇妙なことが起こっています..
実際のページを介して送信する場合.. www.mydomain.com/mail.php 正常に送信され、電子メールの問い合わせが正常に機能します。
ただし、次の連絡先ページに含まれている場合..
<?php include('mail.php'); ?>
メールが 2 回送信されるか、まったく送信されないこともあります。
何か案は?
<?php
if (isset($_POST["mail"]) && ($_POST["mail"]=="send")) {
//ini_set("sendmail_from", "mailserver@thedomain.com");
/******** START OF CONFIG SECTION *******/
//$sendto = "enquiries@rivelintravel.co.uk";
$sendto = "test@thedomain.com";
$subject = "Website Form Test";
$errorImage = "assets/form/exclamation.png";
$acceptImage = "assets/form/accept.png";
/******** END OF CONFIG SECTION *******/
$SpamReplaceText = "*content removed*";
// Error message prited if spam form attack found
$SpamErrorMessage = "<div class=\"contactFormErrorMessage\">Malicious code content detected.<br>Your IP Number of ".getenv("REMOTE_ADDR")." has been logged.</div>";
foreach($_POST as $key => $value) {
$post[$key] = $value;
}
$name = $post['name'];
$email = $post['email'];
// $message = $post['message'];
$headers = "From: $email\n";
$headers . "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 7bit\n"
. "Content-type: text/html; charset = \"iso-8859-1\";\n\n";
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
foreach($post as $key => $value) {
if (preg_match("/http/i", "$post[$key]")) {echo "$SpamErrorMessage"; exit();}
}
// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string
foreach($post as $key => $value) {
$post[$key] = preg_replace($pattern, "", $value);
}
// Check for the injected headers from the spammer attempt
// This will replace the injection attempt text with the string you have set in the above config section
$find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i");
foreach($post as $key => $value) {
$post[$key] = preg_replace($find, "$SpamReplaceText", $value);
}
// Check to see if the fields contain any content we want to ban
foreach($post as $key => $value) {
if(stristr($post[$key], $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
}
// Do a check on the send email and subject text
foreach($post as $key => $value) {
if(stristr($post[$key], $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
}
// Build the email body text
$emailcontent = "Website Form Test" . "\n";
$emailcontent .= "_" . "\n";
$emailcontent .= "Name: " . $_POST['name'] . "\n";
$emailcontent .= "Email: " . $_POST['email'] . "\n";
$emailcontent .= "Telephone Number: " . $_POST['tel'] . "\n";
$emailcontent .= "_" . "\n";
// Check the email address enmtered matches the standard email address format
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $post['email'])) {
echo "<div class=\"contactFormErrorMessage\"><img src=\"$errorImage\" alt=\"Error\" /><p>It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a></p></div>";
}
elseif (!trim($post['name'])) {
echo "<div class=\"contactFormErrorMessage\"><img src=\"$errorImage\" alt=\"Error\" /><p>Please go back and enter a Name</p><p><a href='javascript: history.go(-1)'>Click here to go back</a></p></div>";
}
elseif (!trim($post['email'])) {
echo "<div class=\"contactFormErrorMessage\"><img src=\"$errorImage\" alt=\"Error\" /><p>Please go back and enter an Email</p><p><a href='javascript: history.go(-1)'>Click here to go back</a></p></div>";
}
// Sends out the email or will output the error message
elseif (mail($sendto, $subject, $emailcontent, $headers)) {
echo "<div class=\"contactFormSuccessMessage\"><img src=\"$acceptImage\" alt=\"Success\" /><p>Thank You $name<br />We will be in touch as soon as possible.</p></div>";
}
}else{
?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" id="contactForm" name="contactForm">
<input name="mail" type="hidden" value="send"/>
<div class="content clearfix">
<div class="left">
<h3>Personel Details: </h3>
<div class="field">
<label for="name">Name <span class="required" title="This field is required.">*</span></label>
<input name="name" type="text" />
</div>
<div class="field">
<label for="email">Email Address<span class="required" title="This field is required.">*</span></label>
<input name="email" type="text" />
</div>
<div class="field">
<label for="tel">Contact Number</label>
<input name="tel" type="text" />
</div>
</div>
<!--column1-->
<div id="sub" class="field">
<label for="submit"> </label>
<input class="submit" type="submit" name="submit" value="submit" id"submit" />
</div>
</div>
</div><!--column-->
</fieldset>
</form>
<?php } ?>