I am trying to send mail with HTML and PHP and I can not [closed]

0

Well, it's the following, I've created a form to send a quote from my client's client to my client using the site, but he does not click the "send" button and nothing happens and I'm not understanding why. I'll leave the HTML and PHP here in the description, there goes:

HTML:

<form name="orcamento" action="mail.php">           
            <div id="form-main">
                <div id="form-div">
                    <form class="form" id="form1" method="POST" action="mail.php">
                        <p class="name">
                            <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Nome" id="name" />
                        </p>
                        <p class="email">
                            <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
                        </p>
                        <p class="phone">
                            <input name="tel" type="text" class="validate[required,custom[email]] feedback-input" id="phone" placeholder="Telefone (Com DDD)" />
                        </p>
                        <p class="text">
                            <textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Produtos"></textarea>
                        </p>

                        <div class="submit">
                            <button class="g-recaptcha" data-sitekey="6LdIgR4UAAAAALrbj6sHWoRU6v9zZgDXp71MXQiX" data-callback='onSubmit' name="enviar" type="submit" id="button-blue" formmethod="POST"> ENVIAR </button>
                                <div class="ease"></div>
                                <div class="g-recaptcha"
                                    data-sitekey="6LdIgR4UAAAAALrbj6sHWoRU6v9zZgDXp71MXQiX"
                                    data-callback="onSubmit"
                                    data-size="invisible">
                                </div>
                        </div>
                    </form>
                </div>
        </form>

PHP:

<?php
if($_POST['name'] & $_POST['text'] & $_POST['tel'] != ''){
    include "classes/class.phpmailer.php";
    $GetPost = filter_input_array(INPUT_POST,FILTER_DEFAULT);
    $mensagem = "<html><head><center><img src=\"image/logo-grande.png\"></center></head><body style=\"background-color:#FFF;font-family:Segoe UI;font-site:14px;color:#000;\">
        <br /><br />
        <b>Contato Site ".Config::tituloSite()."</b>
        <br /><br />
        <hr style=\"width:100%;border:1px solid #3399CC\" /><br />
        <b>Nome:</b> ".$_POST['name']."<br /><br />
        <b>E-mail:</b> ".$_POST['email']."<br /><br />
        <b>Telefone:</b> ".$_POST['tel']."<br /><br />
        <b>Mensagem:</b> ".nl2br($_POST['text'])."<br /><br />
        <hr style=\"width:100%;border:1px solid #3399CC\" />
        </body></html>";
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Charset = "UTF-8";
    $mail->SMTPSecure = 'ssl';

    $mail->Host = 'mail.madeireirapadroeira.com.br'; // Endereço do servidor SMTP (Autenticação, utilize o host smtp.seudomínio.com.br)
    $mail->SMTPAuth   = true;  // Usar autenticação SMTP (obrigatório para smtp.seudomínio.com.br)
    $mail->Port       = 587; //  Usar 587 porta SMTP
    $mail->Username = '[email protected]'; // Usuário do servidor SMTP (endereço de email)
    $mail->Password = 'SENHA'; // Senha do servidor SMTP (senha do email usado)

     //Define o remetente
     // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    
    $mail->From = '[email protected]'; 
    $mail->FromName = "ORÇAMENTO-SITE";

     //Define os destinatário(s)
    $mail->AddAddress('[email protected]');         
    $mail->IsHTML(true);
    $mail->Subject = "Contato pelo site - {$_POST['name']}".date("H:i")." - ".date("d/m/Y");
    $mail->Body = $mensagem;

    if($mail->Send()){  
        echo 'E-mail enviado com sucesso!';

    }
    else{
        echo 'Houve algum erro no envio. Tente novamente!'; .$mail->ErrorInfo;
    }
}?>
    
asked by anonymous 05.05.2017 / 01:54

2 answers

0

Your line 43 is wrong, has ; before . :

echo 'Houve algum erro no envio. Tente novamente!'; .$mail->ErrorInfo;

What generates an error like:

  

Parse error: syntax error, unexpected '.' in enviar.php on line 43

The correct one would be this:

echo 'Houve algum erro no envio. Tente novamente!' .$mail->ErrorInfo;

Probably the error does not appear because in php.ini it should look like this:

display_errors=Off

Read more about errors in:

Note about the page

When you open the page link with the browser console, it is possible to notice the lack of Jquery

AndinthesourcecodeyouaddedjQuerytwice:

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script><scriptsrc="https://www.google.com/recaptcha/api.js"asyncdefer></script><scripttype="text/javascript" src="js/modernizr.custom.86080.js"></script>

The first one:

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"asyncdefer></script><scripttype="text/javascript" src="js/modernizr.custom.86080.js"></script>

This is causing a 404 error, remove it, or remove the second and set the script link from "js/jquery-1.10.2.min.js" to "/js/jquery-1.10.2.min.js" , thus:

<script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"asyncdefer></script><scripttype="text/javascript" src="js/modernizr.custom.86080.js"></script>

Another detail in PHP is how Leo said, you used & instead of && , change this:

if($_POST['name'] & $_POST['text'] & $_POST['tel'] != ''){

For this reason

if($_POST['name'] && $_POST['text'] && $_POST['tel'] != ''){

Read about operators in the PHP documentation

05.05.2017 / 02:12
0

In HTML I removed the form that was left over

<div id="form-main">
<div id="form-div">
    <form class="form" id="form1" method="POST" action="">
        <p class="name">
        <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Nome" id="name" />
        </p>
        <p class="email">
        <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
        </p>
        <p class="phone">
        <input name="tel" type="text" class="validate[required,custom[email]] feedback-input" id="phone" placeholder="Telefone (Com DDD)" />
        </p>
        <p class="text">
        <textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Produtos"></textarea>
        </p>
        <div class="submit">
        <button class="g-recaptcha" data-sitekey="6LdIgR4UAAAAALrbj6sHWoRU6v9zZgDXp71MXQiX" data-callback='onSubmit' name="enviar" type="submit" id="button-blue" formmethod="POST"> ENVIAR </button>
            <div class="ease">
            </div>
            <div class="g-recaptcha" data-sitekey="6LdIgR4UAAAAALrbj6sHWoRU6v9zZgDXp71MXQiX" data-callback="onSubmit" data-size="invisible">
            </div>
    </form>
</div>

PHP here was giving errors and as I thought you had already solved, I deleted the error_log folder. So I do not remember exactly the mistakes.

  

One of them was in $mail->Host = 'mail.madeireirapadroeira.com.br';   I fixed to $mail->Host = 'smtp.madeireirapadroeira.com.br';

     

other was Config :: tituloSite () in this line <b>Contato Site ".Config::tituloSite()."</b> which I removed

     

plus if($_POST['name'] & $_POST[.... that has been fixed to if($_POST['name'] && $_POST[ ....

     

note that I have commented $mail->SMTPSecure = 'ssl'; and $mail->Port = 587; since these are not required on my server. I do not know if your server is required. There you have the right tests with and without.

Follow PHP which you received the email sent from my server.

<?php
if($_POST['name'] && $_POST['text'] && $_POST['tel'] != ''){
    require("phpmailer/class.phpmailer.php");
    $GetPost = filter_input_array(INPUT_POST,FILTER_DEFAULT);
    $mensagem = "<html><head><center><img src=\"image/logo-grande.png\"></center></head><body style=\"background-color:#FFF;font-family:Segoe UI;font-site:14px;color:#000;\">
        <br /><br />
        <b>Contato Site</b>
        <br /><br />
        <hr style=\"width:100%;border:1px solid #3399CC\" /><br />
        <b>Nome:</b> ".$_POST['name']."<br /><br />
        <b>E-mail:</b> ".$_POST['email']."<br /><br />
        <b>Telefone:</b> ".$_POST['tel']."<br /><br />
        <b>Mensagem:</b> ".nl2br($_POST['text'])."<br /><br />
        <hr style=\"width:100%;border:1px solid #3399CC\" />
        </body></html>";
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Charset = "UTF-8";
    //$mail->SMTPSecure = 'ssl';
    $mail->Username = '[email protected]'; // Usuário do servidor SMTP

    $mail->Host = 'smtp.madeireirapadroeira.com.br'; // Endereço do servidor SMTP (Autenticação, utilize o host smtp.seudomínio.com.br)
    $mail->SMTPAuth   = true;  // Usar autenticação SMTP (obrigatório para smtp.seudomínio.com.br)
    //$mail->Port       = 587; //  Usar 587 porta SMTP
    $mail->Username = '[email protected]'; // Usuário do servidor SMTP (endereço de email)
    $mail->Password = 'SENHA'; // Senha do servidor SMTP (senha do email usado)

     //Define o remetente
     // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    
    $mail->From = '[email protected]'; 
    $mail->FromName = "ORÇAMENTO-SITE";

     //Define os destinatário(s)
    $mail->AddAddress('[email protected]');        
    $mail->IsHTML(true);
    $mail->Subject = "Contato pelo site - {$_POST['name']}".date("H:i")." - ".date("d/m/Y");
    $mail->Body = $mensagem;

    if($mail->Send()){  
        echo 'E-mail enviado com sucesso!';

    }
    else{
        echo 'Houve algum erro no envio. Tente novamente!' .$mail->ErrorInfo;
    }
}?>
    
05.05.2017 / 02:49