0

我在 joomla 工作,我在其中custom contact form 创建了一个html code,当用户单击submit按钮时,我应该将所有文本框值都email提供给我。

所以我为此写作php code

例如,在 php 代码中的 html 代码中只有两个字段,如下所示

<?php
if(isset($_POST['email'])) {


    $email_to = "test@gmail.com";
    $email_subject = "mail";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // add  validation for other fields if needed 
    if(!isset($_POST['Applicant_name']) ||
        !isset($_POST['email']))) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

     //all fields with there name to send in email
    $name = $_POST['name']; // required
    $email= $_POST['email']; // required


    $error_message = "";

  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

     //show all fields in message body
    $email_message .= "Applicant_name: ".clean_string($Applicant_name)."\n";
    $email_message .= "name: ".clean_string($dob)."\n";
    $email_message .= "email: ".clean_string($sex)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>

我需要在哪里以及如何将此代码粘贴到 Joomla 中?

4

3 回答 3

3

安装一个扩展来处理表单会更容易。

我建议你安装 RSform Pro

特点与优势

  • 发送带有提交数据的自定义 HTML/文本电子邮件
  • 将收集的数据导出为 CSV 格式
  • 字段验证规则可定制的感谢信息
  • 可定制的感谢信息
于 2013-09-30T16:31:50.303 回答
1

如果您决定使用自己的代码,请从 "ADMIN end" 转到模块。单击“新建”,然后选择“自定义 html”类型并简单地粘贴代码。现在给你的模块一个名字,并在你需要的地方发布它。

于 2016-06-08T12:15:39.420 回答
0

为什么不直接使用核心联系表格并制作一个插件来添加一些字段。

于 2013-09-30T22:09:48.660 回答