Jump to content
Fórum Script Brasil
  • 0

Problemas com Formulario


viniciusbr
 Share

Question

Boa tarde tudo bem ? alguém poderia me ajuda? estou com problemas com esse formulario ele não esta enviando

<?php

    /*-------------------------------------------------------------------------------------------*/
    /* This script takes values from the Universe Contact Form and send it to a specified email 
    /* TAKE CARE WHEN EDIT IT - If you need further assistance on how to setup it get in touch
     * through our profile on Theme Forest
    /*-------------------------------------------------------------------------------------------*/
    
    if($_POST)
    {
        $to_Email       = "[email protected]"; // Replace with recipient email address
        $subject        = 'Mensagem de formulário do site'; //Subject line for emails, you can alter it
        
        
        //check if its an ajax request, exit if not
        if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
        
            //exit script outputting json data
            $output = json_encode(
            array(
                'type'=>'error', 
                'text' => 'Request must come from Ajax'
            ));
            
            die($output);
        } 
        
        //check $_POST vars are set, exit if any missing
        if(!isset($_POST["firstName"]) || !isset($_POST["subject"]) || !isset($_POST["userEmail"]) || !isset($_POST["userMessage"]))
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!'));
            die($output);
        }
    
        //Sanitize input data using PHP filter_var().
        $first_Name        = filter_var($_POST["firstName"], FILTER_SANITIZE_STRING);
        $user_subject       = filter_var($_POST["subject"], FILTER_SANITIZE_EMAIL);
        $user_Email       = filter_var($_POST["userEmail"], FILTER_SANITIZE_STRING);
        $user_Message     = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);
        
        //additional php validation
        if(strlen($first_Name)<4) // If length is less than 4 it will throw an HTTP error.
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Nome curto ou campo vazio!'));
            die($output);
        }
        if(strlen($user_subject)<4) // If length is less than 4 it will throw an HTTP error.
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Nome curto ou campo vazio!'));
            die($output);
        }
        if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Por favor insira um e-mail valido!'));
            die($output);
        }
        
        if(strlen($user_Message)<5) //check emtpy message
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Too short message! Please enter something.'));
            die($output);
        }
        
        //proceed with PHP email.
        $headers = 'From: '.$user_Email.'' . "\r\n" .
        'Reply-To: '.$user_Email.'' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
        
            // send mail
        $sentMail = @mail($to_Email, $subject, $user_Message .'  -  Email sent by: '.$first_Name. ' '.$user_subject, $headers);
        
        if(!$sentMail)
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
            die($output);
        }else{
            $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$first_Name .'. Thank you for your email.'));
            die($output);
        }
    }
?>

e os campos do formulario são esses

<form action="assets/includes/contact-form.php" method="post" class="form-group">
								<div class="row">
									<div class="col-md-6 col-sm-6 col-xs-12">
										<input type="text" name="name" id="name" placeholder="Nome (obrigatório)">
									</div>
									<div class="col-md-6 col-sm-6 col-xs-12">
										<input type="email" name="email" id="email" placeholder="Email (obrigatório)">
									</div>
									<div class="col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="subject" id="subject" placeholder="Assunto">
									</div>
									<div class="col-md-12 col-sm-12 col-xs-12">
										<textarea name="message" id="message" cols="39" rows="4" placeholder="Sua Mensagem"></textarea>
									</div>
									<div class="col-md-12 col-sm-12 col-xs-12">
										<input name="submit" type="submit" id="submit" tabindex="5" value="Enviar Mensagem" class="comment-submit t-btn t-btn-primary">
									</div>
								</div>
							</form> <!-- .form-group -->

obrigado.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.9k
    • Total Posts
      646.8k
×
×
  • Create New...