既存のキャプチャ付きの連絡フォームがあります。フォームを作成し、アップロード機能を組み込みました。問題は、キャプチャなしでフォームを送信しようとしたときに js アラートまたは無効なキャプチャ アラートが表示されないことですが、画像を添付しようとしたときにキャプチャなしでフォームを送信すると、送信されます..コードは今めちゃくちゃです. 誰でも条件付きステートメントをチェックして、これを修正するのを手伝ってくれるかどうかを確認できますか? 私はphpが苦手です。
これは私のmail.phpです
<?php
if($_SESSION["captcha"] == $_POST["captcha"]) {
//if($_SESSION["captcha"] == $_POST["captcha"]) {
// we'll begin by assigning the To address and message subject
$to="myemail@gmail.com";
$subject="E-mail with attachment";
// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// store the file information to variables for easier access
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$size = $_FILES['filename']['size'];
// here we'll hard code a text message
// again, in reality, you'll normally get this from the form submission
$message = 'Message from '.$_REQUEST['name'].'
Full Name: '.$_REQUEST['name'].'
Address: '.$_REQUEST['address'].'
Contact Number: '.$_REQUEST['contact'].'
Email: '.$_REQUEST['email'].'
How do you come to know about us: '.$_REQUEST['type'].'
Car Make: '.$_REQUEST['make'].'
Car Model: '.$_REQUEST['model'].'
Year: '.$_REQUEST['year'].'
Registration: '.$_REQUEST['registration'].'
Comment: '.$_REQUEST['comments'].'
';
// if the upload succeded, the file will exist
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// now we just send the message
if (@mail($to, $subject, $message, $headers)){
echo "<script>alert('Your details has been Sent Successfully, we shall revert back to you shortly!!!');</script>";
echo "<script>window.location.href='index.php';</script>";
} else {
echo "<script>alert('Sending Failed');</script>";
echo "<script>window.location.href='index.php';</script>";
} }
} else {
echo "<script>window.location.href='index.php?cap=invalid';</script>";
}
?>
フォームは次のとおりです。
<div class="quote-wrap left">
<form name="quoteForm" enctype="multipart/form-data" method="post" action="mail.php" onsubmit="return validateQuoteForm();">
<div class="quote-table left liquid-size">
<table width="100%">
<tr>
<td colspan="2" align="center" valign="middle" style="padding-bottom:0px;"><?php $qerror ?></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle" style="padding-bottom:0px; color:#FF0000;"><h3><?php $captcha_stat?></h3></td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="make" placeholder="Make:" class="input-field" value="$make" />
<span class="required">*</span>
</td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="model" placeholder="Model:" class="input-field" value="$model" /><span class="required">*</span></td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="year" placeholder="Year:" class="input-field" value="$year"/>
<span class="required">*</span>
</td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="registration" placeholder="Registration:" class="input-field" value="$registration" /><span class="required">*</span></td>
</tr>
</table>
</div>
<div class="quote-table left liquid-size">
<table width="100%">
<tr>
<td valign="middle" align="left">
<input type="text" name="address" placeholder="Full Address:" class="input-field" value="$address" /><span class="required">*</span></td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="name" placeholder="Name:" class="input-field" value="$name"/><span class="required">*</span></td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="contact" placeholder="Contact No:" class="input-field" value="$contact"/><span class="required">*</span></td>
</tr>
<tr>
<td valign="middle" align="left">
<input type="text" name="email" placeholder="Email:" class="input-field" value="$email" /><span class="required">*</span></td>
</tr>
<tr>
<td valign="middle" align="left">How do you come to know about Us?</td>
</tr>
<tr>
<td valign="middle" align="left">
<select class="quotable-select" name="type">
<option value="Google search">Google search</option>
<option value="Yahoo search">Yahoo search</option>
<option value="Bing search">Bing search</option>
<option value="Hotfrog">Hotfrog</option>
<option value="Local Newspaper">Local Newspaper</option>
<option value="Magazine">Magazine</option>
<option value="Returning Customer">Returning Customer</option>
<option value="Heard about us">Heard about us</option>
<option value="Saw us on the road">Saw us on the road</option>
<option value="Referral">Referral</option>
<option value="Facebook">Facebook</option>
<option value="Trademe">Trademe</option>
<option value="Yellow Online">Yellow Online</option>
</select>
</td>
</tr>
</table>
</div>
<table width="100%">
<tr>
<td colspan="2" align="left" class="required" valign="middle">
<span class="required">Note: Image must not be greater than 1MB.</span>
</td>
</tr>
<tr>
<td valign="middle" align="left" wid>
Attach Photos:
<input type="file" id="fileupload" name="filename" border="0" />
</td>
</tr>
<tr>
<td valign="middle" align="left">
<textarea class="quote-txtarea" placeholder="Comments:" name="comments" rows="3" cols="22">$comments</textarea>
</td>
</tr>
<tr>
<td valign="top" >
<img src="captcha.php" name="captcha" id="captcha" style="padding: 0px; margin: 0 0 -4px;" />
<input class="input" type="text" name="captcha" style="width:100px; height: 20px; padding: 0px;" />
<input type="submit" name="submit_quote" class="submit" value="Submit" />
</td>
</tr>
</table>
</form>
</div>