PHP言語の初心者として、Javascript検証コードとともにhtmlコーディングを使用してphp連絡フォーム(contact.php)をセットアップしました。完了すると、送信されず、指定された電子メールIDに送信されません。本当に、問題が発生したコードを把握できませんでした。以下のコードを確認して、これを修正するのを手伝ってくれませんか?
<?php
// Set email variables
$email_to = 'contact@mycompany.com';
$email_subject = 'New Contact Form Submission';
/* Gathering Data Variables */
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$message = $_POST['message'];
$ipaddress = $_POST['ipaddress'];
$body = <<<EOD
<br><hr><br>
Full Name: $fullname <br>
Email: $email <br>
Phone: $phone <br>
Country: $country <br>
Message: $message <br>
Submitted By IP: $ipaddress <br>
EOD;
$headers = "From: $fullname\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);
// Set required fields
$required_fields = array('fullname','email','country','message');
// set error messages
$error_messages = array(
'fullname' => 'Please enter Your Name to proceed.',
'email' => 'Please enter a valid Email Address to contact.',
'country' => 'Please enter your country of residence.',
'message' => 'Please enter your message.'
);
// Set form status
$form_complete = FALSE;
// configure validation array
$validation = array();
// check form submittal
if(!empty($_POST)) {
// Sanitise POST array
foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
// Loop into required fields and make sure they match our needs
foreach($required_fields as $field) {
// the field has been submitted?
if(!array_key_exists($field, $_POST)) array_push($validation, $field);
// check there is information in the field?
if($_POST[$field] == '') array_push($validation, $field);
// validate the email address supplied
if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
}
// basic validation result
if(count($validation) == 0) {
// Prepare our content string
$email_content = 'Contact Form Submission Received: ' . "\n\n";
// simple email content
foreach($_POST as $key => $value) {
if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
}
// if validation passed ok then send the email
mail($email_to, $email_subject, $email_content);
// Update form switch
$form_complete = TRUE;
}
}
function validate_email_address($email = FALSE) {
return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
}
function remove_email_injection($field = FALSE) {
return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}
?>
フォーム開始
<?php if($form_complete === FALSE): ?>
<form name="contact_form" method="post" id="contact_form" action="contacts.php" onsubmit="return defaultagree(this)"><table width="430" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="left"><table width="430" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle" align="right" width="130" class="offerformtext"><span>*</span> Name:</td>
<td valign="top" align="left" width="300" class="mbox"><input name="fullname" id="fullname" type="text" class="offer_input_box" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" align="left"><table width="430" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle" align="right" width="130" class="offerformtext"><span>*</span> Email:</td>
<td valign="top" align="left" width="300" class="mbox"><input name="email" id="email" type="text" class="offer_input_box" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" align="left"><table width="430" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle" align="right" width="130" class="offerformtext">Phone:</td>
<td valign="top" align="left" width="300"><input name="phone" id="phone" type="text" value="" class="offer_input_box" /></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" align="left"><table width="430" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle" align="right" width="130" class="offerformtext"><span>*</span> Country:</td>
<td valign="top" align="left" width="300" class="mbox"><input name="country" id="country" type="text" class="offer_input_box" value="<?php echo isset($_POST['country'])? $_POST['country'] : ''; ?>" /></textarea><?php if(in_array('country', $validation)): ?><span class="error"><?php echo $error_messages['country']; ?></span><?php endif; ?></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" align="left"><table width="430" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="right" width="130" class="offerformtext"><span>*</span> Message:</td>
<td valign="top" align="left" width="300" class="mmbox"><textarea name="message" id="message" class="offer_message_box" value="<?php echo isset($_POST['message'])? $_POST['message'] : ''; ?>" /></textarea><?php if(in_array('message', $validation)): ?><span class="error"><?php echo $error_messages['message']; ?></span><?php endif; ?></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="bottom" align="center" class="subdown"><input name="submit" type="Submit" class="offer_submit_button" value=""/><br /><br /></td>
</tr>
<tr>
<td><input type="hidden" name="ipaddress" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" /></td>
</tr>
</table>
</form>
<?php else: ?>
<h2 style="font-family:'Times New Roman', Times, serif; font-size:24px; color:#6d6d6d; font-weight:bold;">Contact Form Successfully Submitted</h2>
<p style="font-family:'Times New Roman', Times, serif; font-size:18px; color:#255E67; margin-left:25px; margin-top:15px;">Thank you for your get in touch with us! We would get back to you regarding this information soon.</p>
<script type="text/javascript">
setTimeout('ourRedirect()', 8000)
function ourRedirect(){
location.href='contacts.php'
}
</script>
<?php endif; ?>
<script>
document.forms.contact_form.agreecheck.checked=false
</script>
フォームエンド
これらは私が使用したコードです。この件に関して私を助けてください。前もって感謝します。