I can’t send contact form. The message "Incorrect email! appears when you click to send

Asked

Viewed 131 times

0

I’m trying to get a contact form, he didn’t have the code in php, only in html, and in the action function of the HTML code he sent to the site https://mobirise.com/.

Example - HTML As was:

<form action="https://mobirise.com/" method="post" data-form-title="INSCREVA-SE" class="">

                        <input type="hidden" value="xF2wyA3Am9XJfPWKPUBHNyYWvEGJICdaXxc9CFcjWrbWYGSdCv/fixi4T+1Vwwm0ndVitrKbaxtbtlwtaxG18eSbhyRi2OJog/+SyB+sMh6+6cl1NPdxVeoqfOgxNecW" data-form-email="true">

After creating the php code I removed from the HTML code the link that was in the action function(https://mobirise.com/) and replace by putting in place
the page ("enviar_email.php" ) I created with php code.

After making these changes in order to make the form send the message to the website email, I have the following problem: after filling the form and clicking send the message "Incorrect email!" appears. I need to solve this problem, so I can check if the php code will work and send the information correctly to the site.

HTML - part of the code I changed:

<form method="post" action="enviar_email.php"  data-form-title="INSCREVA-SE">          

HTML of Fomulário:

<!DOCTYPE html>
<html>
<head>

<section class="mbr-section" id="form1-0"
         style="background-color: rgb(11, 66, 128); padding-top: 40px; padding-bottom: 40px;">

    <div class="mbr-section mbr-section__container mbr-section__container--middle">
        <div class="container">
            <div class="row">
                <div class="col-xs-12 text-xs-center">
                    <h3 class="mbr-section-title display-2">&nbsp;</h3>

                    <h3 class="mbr-section-title display-2">CONTATE-NOS</h3>
                    <small class="mbr-section-subtitle">Deixe seu nome, e-mail e receba mais informações.</small>
                </div>
            </div>
        </div>
    </div>
    <div class="mbr-section mbr-section-nopadding" >
        <div class="container">
            <div class="row">
                <div class="col-xs-12 col-lg-10 col-lg-offset-1" data-form-type="formoid">


                    <div data-form-alert="true">
                        <div hidden="" data-form-alert-success="true"
                             class="alert alert-form alert-success text-xs-center">Muito Obrigado! Em breve
                            retornaremos.
                        </div>
                    </div>


                    <form method="post" action="enviar_email.php"  data-form-title="INSCREVA-SE"> <!-- os dados serão enviados para a página que está definida no action=' ' -->                     

                     

                        <div class="row row-sm-offset">

                            <div class="col-xs-12 col-md-6">
                                <div class="form-group">
                                    <label for="form1-0-name" class="form-control-label style9">Nome</label>
                                    <input type="text" class="form-control" name="name" required=""
                                           data-form-field="Name" id="form1-0-name"> <!-- observa o name em cada um dos campos -->
                                </div>
                            </div>

                            <div class="col-xs-12 col-md-6">
                                <div class="form-group">
                                    <label for="form1-0-email" class="form-control-label style9">E-mail</label>
                                    <input type="email" class="form-control" name="email" required=""
                                           data-form-field="Email" id="form1-0-email">
                                </div>
                            </div>


                        </div>

                        <div class="form-group">
                            <label for="form1-0-message" class="form-control-label style9">Mensagem</label>
                            <textarea class="form-control" name="message" rows="7" data-form-field="Message"
                                      id="form1-0-message"></textarea>
                        </div>

                        <div>
                            <button type="submit" class="btn btn-warning">ENVIAR</button>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
   
</body>
</html>

Form Code - PHP

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
</head>
<body>

<?
//isset checa se o botão enviar - submit foi clicado e só vai disparar o email se for verdadeiro
	
if(isset($_POST['submit'])){

    // email onde tu vai receber a mensagem
    $destinatario = '[email protected]';
    
	// pegando os dados do form...
    $name = $_POST['name'];
	$email = $_POST['email'];
	$mensagem= $_POST['message'];

  // headers que prepara a mensagem	
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type: text/html; charset=utf-8" . "\r\n"; 
    $headers .= "From: Site <[email protected]>" . "\r\n";
    $headers .= "Reply-To: [email protected]" . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();


/*abaixo contém os dados que serão enviados para o email
cadastrado para receber o formulário*/

       $corpo = "Formulario Enviado\n";
       $corpo .= "Nome: " . $name . "\n";
       $corpo .= "E-mail: " . $email . "\n";
       $corpo .= "Mensagem: " . $mensagem . "\n";
	

    // envia o email... -->	
	$resposta = mail($destinatario,$headers,$corpo, $mensagem);

    // volta para contato.html -->
    header("Location: index.php");
}
?>

</body>
</html>

Message that appears when clicking send button inserir a descrição da imagem aqui

JS Code - Formoid

`code` jQuery(function(t){var e=function(){var e=("https:"==location.protocol?"https:":"http:")+"//formoid.net/api/push",a=function(){var e=(/MSIE (\d+)\./.exec(navigator.userAgent)||[0,0])[1]
return 8==e||9==e&&"file:"!=location.protocol?function(e,a){var n=new XDomainRequest,r=t.Deferred()
return n.open(a.type,e),n.onload=function(){r.resolve(this.responseText)},n.onerror=function(){r.reject()},n.send(a.data),r}:(t.support.cors=!0,t.ajax)}(),n=function(t,e){return t="__"+t+"__",e.length?(this[t]=e[0],this):this[t]},r=function(e,a,n){return t.each(n,function(t,n){e[n]=function(){return a[n].apply(a,arguments)}}),e},i=function(t){t=t||{},this.__email__=t.email||"",this.__title__=t.title||"",this.__data__=t.data||[]}
return i.prototype.email=function(t){return n.call(this,"email",arguments)},i.prototype.title=function(t){return n.call(this,"title",arguments)},i.prototype.data=function(t){return n.call(this,"data",arguments)},i.prototype.send=function(n,i){var o=r(t.Deferred(),this,["email","title","data","send"])
return i&&(i.call(this,o),"pending"!=o.state())?o:(a(e,{type:"POST",data:JSON.stringify({email:this.__email__,form:{title:this.__title__,data:arguments.length?n:this.__data__}})}).done(function(t){try{var e=JSON.parse(t)
e.error?o.reject(e.error):o.resolve(e.response)}catch(a){o.reject("Incorrect server response.")}}).fail(function(){var t="Failed to query the server. "
t+="onLine"in navigator&&!navigator.onLine?"No connection to the Internet.":"Check the connection and try again.",o.reject(t)}),o)},{Form:function(t){return new i(t)}}}(),a=function(e){if(e.checkValidity)return e.checkValidity()
var a=!0,n=t(e).val(),r=t(e).attr("type")
return n?a=!("email"===r&&!/^([^@]+?)@(([a-z0-9]-*)*[a-z0-9]+\.)+([a-z0-9]+)$/i.test(n)):t(e).attr("required")&&(a=!1),t(e)[(a?"remove":"add")+"Class"]("form-invalid"),a}
t('[data-form-type="formoid"]').each(function(){var n,r=t(this),i=r.is("form")?r:r.find("form"),o=r.find("[data-form-alert]"),s=r.is("[data-form-title]")?r:r.find("[data-form-title]"),l=r.find('[type="submit"]'),c=o.attr("data-success")||o.find("[data-form-alert-success]").html()
l.html('<span class="btn-text">'+l.html()+'</span><i class="btn-loader"></i>').click(function(){i.addClass("form-active")}),i.submit(function(d){if(d.preventDefault(),i.addClass("form-active"),!l.hasClass("btn-loading")){var f=!0,u=[]
n=n||e.Form({email:r.find("[data-form-email]").val(),title:s.attr("data-form-title")||s.text()}),o.html(""),r.find("[data-form-field]").each(function(){a(this)||(f=!1),u.push([t(this).attr("data-form-field")||t(this).attr("name"),t(this).val()])}),f&&(l.addClass("btn-loading").prop("disabled",!0),n.send(u).done(function(e){i.removeClass("form-active"),r.find("[data-form-field]").val(""),o.append(t('<div class="alert alert-form alert-success text-xs-center"/>').text(c||e))}).fail(function(e){o.append(t('<div class="alert alert-form alert-danger text-xs-center"/>').text(e))}).always(function(){l.removeClass("btn-loading").prop("disabled",!1)}))}})})})

  • Where does this message appear? After it sends the form or before?

  • It does not send the form, when I click send it appears the message.

  • Appears where?...

  • Hey Sam, I edited the question and added the screen print

  • This is some plugin that is doing this. You have to see all the JS code of the page.

  • I think I found the JS code where it can contain the problem, has a JS indexed with the name formoid.min.js

  • Here’s a JS file that must be wrong for validation, and just see which JS file is being called and try without that same file.

Show 2 more comments

1 answer

0

I will leave here just 1 example as I am using phpmailer for sending contact form, can help.

Html

<form class="form-contact contact_form" action="processa_contacto.php" method="post" id="contactForm">
        <input type="hidden" name="recaptcha_response" id="recaptchaResponse">
        <div class="row">
          <div class="col-12">
            <div class="form-group">
                <textarea class="form-control w-100" name="messagem" id="mensagem" cols="30" rows="9" placeholder="Escreva a sua mensagem" required></textarea>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="form-group">
              <input class="form-control" name="nome" id="name" type="text" placeholder="Nome" required>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="form-group">
              <input class="form-control" name="email" id="email" type="email" placeholder="Email" required>
            </div>
          </div>
          <div class="col-12">
            <div class="form-group">
              <input class="form-control" name="assunto" id="assunto" type="text" placeholder="Assunto" required>
            </div>
          </div>

          <div class="col-12">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
                    <label class="form-check-label" for="invalidCheck">
                        <font color="black">RGPD</font>             
                    </label>
                </div>  
          </div>
        </div>
        <div class="form-group mt-3">
          <button type="submit" name="enviar" class="button button-contactForm">Enviar Mensagem</button>
            <br>
        </div>
      </form>

PHP - Sending Contact Request

function send_mail_auth($to_email, $to_name, $from_email, $from_name, $subjectEmpresa, $subjectClient, $body) {
        require_once("sistema/mail/class.phpmailer.php");
        require_once("sistema/mail/class.smtp.php");

        $mail             = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPAuth   = true;
        $mail->SMTPSecure = "ssl";
        $mail->Host       = "teste.development.pt";
        $mail->Port       = 465;
        $mail->Username   = "[email protected]";
        $mail->Password   = "*****";
        //$mail->AddReplyTo($email_remetente,$nome_remetente);
        $mail->From = $from_email;
        $mail->FromName = $from_name;
        $mail->Subject = $subject;
        $mail->WordWrap = 50;
        $mail->AltBody = "Para ver este e-mail, utilize um cliente de e-mail que suporte HTML.";
        $mail->MsgHTML($body);
        $mail->AddAddress($to_email, $to_name);
        $mail->IsHTML(true);
        $mail->Send();

        $mail->ClearAddresses();
        $mail->ClearAttachments();

    }

if(isset($_POST['enviar'])){
                $to_empresa = "[email protected]";
                $to_name = '<strong>Nome:</strong> '.$_POST['nome'].'<br>';
                $email ='<strong>Email:</strong> '.$_POST['email'].'<br>';
                $assunto ='<strong>Assunto:</strong> '.$_POST['assunto'].'<br><br>';
                $texto= $_POST['messagem'];
                $from_email = "[email protected]";
                $from_name = "Teste"; 
                $subjectEmpresa = "TesteEmpresa - Novo pedido de contacto"; 


                include('emailtemplate/emailEmpresa.php');
                send_mail_auth($to_empresa,$to_name, $from_email, $_POST['nome'], utf8_decode($subjectEmpresa), utf8_decode($body));

                $subjectClient = "Teste"; 
                $to_email = $_POST['email'];        

                include('emailtemplate/emailCliente.php');
                send_mail_auth($to_email,$to_name, $from_email, utf8_decode($from_name), utf8_decode($subjectClient), utf8_decode($body));  

            }   

It is also necessary to have the Phpmailer library at the root of the site, in this case I also have the mail template because I am sending 2 different emails, one that is a copy to who sends the form and another email that will be the email sent to the company.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.