我的联系表单的PHP脚本无法正常工作

时间:2014-04-04 19:19:09

标签: php html css joomla

您好我已经编写了以下代码,用于我用joomla创建的网站的联系我们表单。该表单显示在网站website link中,但我有两个问题 1.“消息部分”它的标题位于textarea框的底部,而不是顶部 2.我不是专业编码人员,特别是PHP。当我输入并按提交时没有任何反应。我认为我的php不起作用。

<form id="contact-form" method="post">



            <label for="name">اسم</label>
            <input type="text" name="name" id="name" value=""/> <br>


            <label for="email">ایمیل</label>
            <input type="text" name="email" id="email" value="" /><br>


            <label for="message">پیام</label>
            <textarea name="message" id="message" cols="20" row="50" ></textarea> <br>

     <input type="submit" name="submit" value="Submit" id="submit" />



</form>

<style type="text/css">

form
{
display: inline-block;
    text-align: center;
font-family: "arial";
border:2px solid gray;
margin: 0px auto;
width: 900px;
height: 550px;

background: #580000;}

input
{
border: 1px solid black;
margin: 10px;
font-size: 15px;
}

textarea
{
border: 1px solid black;
margin: 10px;
font-size: 15px;
resize: none;
width: 200px;
height: 250px;

background: #fff;


}

#submit {
    background-color: #000;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius:6px;
    color: #000;
    font-family: 'Oswald';
    font-size: 15px;
    text-decoration: none;
    cursor: poiner;
     border:none;
}



#submit:hover {
    border: none;
    background:grey;
    box-shadow: 0px 0px 1px #777;
}
</style>


<?php
$ToEmail = 'evelina@jfaproduction.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>

1 个答案:

答案 0 :(得分:0)

这是一个使用Joomla编码标准的模型。我只是这样向你展示,因为你似乎非常渴望坚持使用Sourcerer。

<强> HTML:

<form action="" id="contact-form" method="post">
      <label for="name">اسم</label>
      <input type="text" name="name" id="name" value=""/> <br>

      <label for="email">ایمیل</label>
      <input type="text" name="email" id="email" value="" /><br>

      <label for="message">پیام</label>
      <textarea name="message" id="message" cols="20" row="50" ></textarea> <br>

      <input type="submit" name="submit" value="Submit" id="submit" />
</form>

<强> PHP:

<?php
   $mailer = JFactory::getMailer();
   $input = JFactory::getApplication()->input;
   $post = $input->post;  
   $submit = $post->get('submit');

   if(isset($submit) {

       $mailer->setSender($post->get('email'));
       $mailer->addRecipient('evelina@jfaproduction.com');

       $body = 'Name: ' . $post->get('name');
       $body .= 'Email: ' . $post->get('email');
       $body .= 'Message: ' . $post->get('message');

       $mailer->setSubject('Site contact form');
       $mailer->setBody($body);

       $send = $mailer->Send();
       if ( $send !== true ) {
           echo 'Error sending email';
       } 
       else {
           echo 'Success!';
       }

   }

?>