Я знаю 0 о drupal и, к сожалению, не имею большого контроля над модулями и тому подобным.Drupal - Custom form submit
Это было сказано ... Мне нужно отправить форму электронной почте получателю, это довольно стандартная форма с прикрепленным файлом. У меня есть сценарий, который был предварительно написан для меня и подтвержден, работая на отдельном сайте PHP. Однако я сталкиваюсь с некоторыми проблемами, использующими его на drupal. В основном я получаю ошибку 405 Not Allowed при отправке формы ... У нас есть программное обеспечение для отслеживания, которое обычно обрабатывает наши формы, к сожалению, оно не может обрабатывать вложения файлов, поэтому мне нужно использовать собственный скрипт PHP для отправки электронная почта. Сценарий выполнен таким образом, чтобы сочетаться с нашим программным обеспечением для отслеживания, чтобы мы могли отслеживать формы.
На этой странице представлен код 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 = "[email protected]";
//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.");
?>