简体   繁体   中英

my php script for contact form is not working

Hello I have wrote the following code, for a contact us form for my website which I am creating with joomla. The form gets displayed in the website website link but I have two issues 1. The "message part" the title of it falls at the bottom of the textarea box and not at the top 2. i am not a pro coder, specially in PHP. when I type and press submit nothing happens. I assume my php doesn't work.

<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");
?>

Here is a mockup using Joomla coding standards. I'm only showing you this way as you seem quite keen to stick to using 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!';
       }

   }

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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