PHP 언어의 초보자로서 저는 자바 스크립트 유효성 검사 코드와 함께 HTML 코드로 PHP 문의 양식 (contact.php)을 설정했습니다. 완료되면 모든 일들이 제출되지 않고 주어진 이메일 ID로 전송됩니다. 정말로 문제가 발생한 코드를 파악할 수 없었습니다. 아래 코드를 확인하고이를 해결할 수 있도록 도와 주시겠습니까? 양식 시작PHP 양식 제출 오류를 수정하는 방법?
<?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>
양식 끝
<?php
// Set email variables
$email_to = '[email protected]';
$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][email protected]([-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));
}
?>
이 내가 사용했던 코드는,이 문제에 대해 저를 도와주세요하십시오. 미리 감사드립니다.
제어 코드가'mail()'코드 줄에 도달합니까? –
감사합니다. Hanky.하지만 내 이메일에는 아무 것도 없습니다. 도와주세요. – Sumu
@Sumu'$ webMaster' 변수는 어디에도 설정되어 있지 않으므로 송신 할 곳을 알지 못합니다. 'it = form_message' ;-) 당신은 또한 아래의 'amigura's' 대답을 사용할 수 있습니다. –