私は drupal について何も知りませんが、残念ながらモジュールなどをあまり制御できません。
とは言うものの...フォームにメールを受信者に送信させる必要があります。これは、ファイルが添付された非常に標準的なフォームです。私のために事前に作成されたスクリプトがあり、別の PHP サイトで動作することが確認されています。ただし、drupalで使用するといくつかの問題が発生します。基本的に、フォームの送信時に 405 Not Allowed エラーが発生します... 通常、フォームの送信を処理する追跡ソフトウェアがありますが、残念ながら添付ファイルを処理できないため、送信するにはカスタム PHP スクリプトを使用する必要があります。 Eメール。スクリプトは、フォームの送信を引き続き追跡できるように、追跡ソフトウェアとペアになるように作成されています。
コードが配置されているページは、type の PHP コードとして設定されます。(完全な html またはフィルター処理された html とは対照的に)。サーバー上のファイルは一時的に chmod 777 になっていますが、必要なのは 666 だけですよね?
この 405 Not Allowed エラーが発生するのはなぜですか?
ここにいくつかのコードがあります:
フォームの HTML:
<form id="contact-form" action="/sites/www.mathistire.com/files/mailfile-job.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td><label title="Name">Name:</label></td><td><input type="text" name="Name" /></td>
</tr>
<tr>
<td><label title="E-Mail">E-Mail:</label></td><td><input type="email" name="EMail" /></td>
</tr>
<tr>
<td><label title="Position">Position:</label></td><td><input type="text" name="Position" /></td>
</tr>
<tr>
<td><label title="Attach">Attach File:</label></td><td><input type="file" name="import_file" alt="import_file" title="import_file" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" /></td>
</tr>
</table>
</form>
PHP メールファイル:
<?php
ini_set('upload_max_filesize','24M');
ini_set('post_max_size','32M');
if ($_POST) {
$field_tracking = "";
$now = date("D m/d/Y H:i:s e");
// case normalized list of field names that we don't want to encapsulate in xml
$metafieldnames = array("submit","imemailsubject","imredirect","formname","imdefaultrecipient","import_file","max_file_size","x","y");
// build the email message from the list of fields list
$emailxtra="INFORMATION FROM WEB FORM: ".$_POST['formname'].": " . $now . "\n\n";
//check for post values
while(list($key, $value) = each($_POST)) {
if(is_array($value)){
$value = implode(', ',$value);
}
//add value to scope
$$key = $value;
// only encapsulate fields that are not metadata fields or submit button
if (!in_array (strtolower($key), $metafieldnames) ) {
$emailxtra=$emailxtra.$key.": ".stripslashes($value)."\r\n\r\n";
$field_tracking .= "\nurl += '&".$key."=' + escape('".addslashes($value)."');";
}
}
//echo ('FIELD TRACKING: ' . $field_tracking);
//create the email
$mime_boundary = "<<<--==+X[".md5(time())."]";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$imEmailField."\r\n";
$headers .= "Reply-To: ".$EMail."\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";
$mail_message = "This is a multi-part message in MIME format.\r\n\r\n";
$mail_message .= "--".$mime_boundary."\r\n";
$mail_message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$mail_message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$mail_message .= $emailxtra."\r\n";
$upload_error = "";
if ($_FILES && count($_FILES) > 0) {
//upload file 1
if (is_uploaded_file($_FILES['import_file']['tmp_name'])) {
if(preg_match("/.exe$|.com$|.bat$|.rar$|.egs$/i", $_FILES['import_file']['name'])){
$upload_error = "Attempted to upload .exe .com .rar .egs or .bat file.";
}
//echo ('file uploaded');
}
else {
switch($_FILES['import_file']['error']){
case 0: //no error; possible file attack!
$upload_error = "no error; possible file attack!";
break;
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
$upload_error = "uploaded file exceeds the upload_max_filesize directive in php.ini.";
break;
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
$upload_error = "uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.";
break;
case 3: //uploaded file was only partially uploaded
$upload_error = "uploaded file was only partially uploaded.";
break;
case 4: //no file was uploaded
$upload_error = "No file was uploaded.";
break;
default: //a default error, just in case! :)
$upload_error = "There was a problem with your upload.";
break;
}
}
if ($upload_error != "") {
$mail_message .= "ERROR with attachment 1 file ".$_FILES['import_file']['name'].": ".$upload_error."\r\n";
}
else {
$mail_message .= "--".$mime_boundary."\r\n";
$mail_message .= "Content-Type: application/octet-stream;\r\n";
$mail_message .= " name=\"".$_FILES['import_file']['name']."\"\r\n";
$mail_message .= "Content-Transfer-Encoding: base64\r\n";
$mail_message .= "Content-Disposition: attachment;\r\n";
$mail_message .= " filename=\"".$_FILES['import_file']['name']."\"\r\n";
$mail_message .= "\r\n";
$fp = fopen($_FILES['import_file']['tmp_name'],"r");
$contents = fread ($fp, filesize($_FILES['import_file']['tmp_name']));
fclose($fp);
$contents = chunk_split(base64_encode($contents));
//echo $contents;
//$mail_message .= strip_tags($contents);
$mail_message .= $contents;
//$mail_messagee .= "\r\n";
//$mail_message .= "--".$mime_boundary."\r\n";
}
} //close check for files
$recipient = "mhostiuckproductions@gmail.com";
//echo $mail_message;
mail($recipient,$subj_slug,$mail_message,$headers);
} //close post check
//Insite
$url = "http://www.insitemetrics.com/imv2/uRMJ/uniformv2.php?actk=6vdsc0-5yfrjtbfcq" .
"&Name=" . $_REQUEST['Name'] .
"&EmailField=" . $_REQUEST['EMail'] .
"&Position=" . $_REQUEST['Position'] .
"&FileAttach=" . $_FILES['import_file']['name'];
header("location:".$url);
exit;
//echo ("mail sent.");
?>