I'm trying to send email with HTML and PHP and I can't [closed]

closed . This question needs details or to be clearer and is not currently accepting answers.

Want to improve this question? Add details and make it clearer what problem is being solved by editing this post .

Closed 3 years ago .

improve this question

Well, this is the following, I created a form to send a quote from my client's client to my client using the site, but do not click on the "submit" button nothing happens and I'm not understanding why. I'll leave HTML and PHP here in the description, there it 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;
    }
}?>
Author: Guilherme Nascimento, 2017-05-04

2 answers

Your line 43 is wrong, has a ; before .:

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

Which generates an error like:

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

The correct 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 at:


Note on page

When opening the page link with the browser console logo it is possible to notice the lack of jQuery

error

And in the source code vc added jQuery twice:

<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>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script type="text/javascript" src="js/modernizr.custom.86080.js"></script>

The first:

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

Is causing error 404, remove it, or remove the second one and adjust 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" async defer></script>
<script type="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

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

Read about operators in PHP documentation

 0
Author: Guilherme Nascimento, 2017-05-05 01:04:33

In HTML I removed the form that was left

<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 don't remember exactly the mistakes.

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

Another was Config:: tituloSite() on that line <b>Contato Site ".Config::tituloSite()."</b> which I removed

More in if($_POST['name'] & $_POST[.... that has been fixed for if($_POST['name'] && $_POST[ ....

Notice tb that I commented $mail->SMTPSecure = 'ssl'; and $mail->Port = 587; as these are not needed on my server. No I know if on your server are required. Ai you do the proper tests with and without.

Follows the 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;
    }
}?>
 0
Author: Leo Caracciolo, 2020-06-11 14:45:34