繁体   English   中英

将 php 脚本转换为 Joomla 模块 3.2.3

[英]Convert php script into a Joomla Module 3.2.3

我用 html 表单编写了这个 php 脚本,该表单发送通过电子邮件输入的所有数据。 如何将其转换为 joomla 3.2.3 的模块? 我四处寻找,但不幸的是我没有找到任何东西。

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
<table border="0">
<caption align="center"><h3>FORM</h3></caption>
<tr>
  <td>Your Mail:</td>
  <td><input type="text" name="sender_mail" value="" /></td>
</tr>
<tr>
  <td>Name:</td>
  <td><input type="text" name="name" value="" /></td>
</tr>
<tr>
  <td>Description:</td>
  <td><textarea cols="50" rows="10" name="description" style="resize:none"></textarea></td>
  </tr>
  <tr>
  <td>Address:</td>
  <td><input type="text" name="address" /></td>
</tr>
<tr>
  <td>Image:</td>
  <td><input type="file" name="attachFile" /></td>
</tr>
  <tr><td><h4>Images:</h4></td></tr>
<tr>
  <td><input type="file" name="attachFile1" /></td>
</tr>
<tr>
  <td><input type="file" name="attachFile2" /></td>
</tr>
<tr>
  <td><input type="file" name="attachFile3" /></td>
</tr>
<tr>
  <td><input type="file" name="attachFile4" /></td>
</tr>
<tr>
  <td><input type="file" name="attachFile5" /></td>
</tr>
<tr>
  <td colspan="2"><input type="submit" name="send" value="send" /></td>
</tr>
</table>
</form>

<?php
if(isset($_POST['send']))
{
$to = "email@example.com";
$subject= "subject";
$todayis = date("l, F j, Y, g:i a") ;
$name = $_POST['name'];
$description = $_POST['description'];
$address = $_POST['address'];
$email = $_POST['sender_mail'];
$message = "
Date: $todayis
Name: $name
description:\n$description\n
address: $address";

  $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
         $headers = "From: $email\r\n" .
         "MIME-Version: 1.0\r\n" .
            "Content-Type: multipart/mixed;\r\n" .
            " boundary=\"{$mime_boundary}\"";
         $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";
         foreach($_FILES as $userfile)
         {
            $tmp_name = $userfile['tmp_name'];
            $type = $userfile['type'];
            $name = $userfile['name'];
            $size = $userfile['size'];
            if (file_exists($tmp_name))
            {
               if(is_uploaded_file($tmp_name))
               {
                  $file = fopen($tmp_name,'rb');
                  $data = fread($file,filesize($tmp_name));
                  fclose($file);
                  $data = chunk_split(base64_encode($data));
               }
               $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";
            }
         }
         $message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
   echo "Mail sent successfully.";
else
   echo "Error in mail";
}
?>

我希望你能帮助我。

这里有一些关于如何为Joomla 2.5+创建简单模块的文档

通常,默认情况下,模块有大约 3 个文件……但根据您的 Joomla,它们可以有更多文件。

文件结构。

mod_yourmodule.php(这真的有重定向使用到 default.php 文件的基本代码......请参阅默认 Joomla 模块的 mod_login.php 文件。 ) mod_yourmodule.xml(这将包含所有作者信息和名称你的模块再次大约几次......再次,看看默认的 mod_login.xml

tmpl/default.php (这将包含您的大部分代码......您刚刚粘贴在顶部的内容)。

对于初学者。 - Joomla 基于 PHP 并且工作方式大致相同...因此,您可以使用上面相同的表单并将其发布到当前页面并使用 jRequest 获取所有输入值。 http://docs.joomla.org/J1.5:Retrieving_and_Filtering_GET_and_POST_requests_with_JRequest::getVar

现在......我相信你已经到了你的模块有点工作的地步,你可以在这里寻求支持......如果没有,你总是可以使用像Rsform这样的东西在几秒钟内获得一个表格.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM