I’m trying to send email with HTML and PHP and I can’t

Asked

Viewed 134 times

0

Well, the thing is, I created a form to send a quote from my client to my client using the site, but do not click the "send" button anything happens and I do not understand 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;
    }
}?>
  • what are two Forms <form name="orcging" action="mail.php">

  • It was for testing but it makes no difference with or without

  • is working now? you received an email I made here for testing with your corrected code?

  • Yes, I did, Leo, but in the test I did right on the website, no, I just did, two minutes ago

  • Uai, but Guilherme Nascimento’s answer is marked as accepted, so I thought I’d got it right.

  • Dei accepted because the && error was not what I was asking

Show 1 more comment

2 answers

0


Your line 43 is wrong, there’s a ; before the .:

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

This would be right:

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

Probably the error does not appear because in php.ini must be like this:

display_errors=Off

Read more about errors in:


Note on the page

When opening the page link with the browser console soon it is possible to notice the lack of Jquery

erro

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>

This causing error 404, remove it, or else remove the second and adjust the link from the script "js/jquery-1.10.2.min.js" for "/js/jquery-1.10.2.min.js", being like this:

<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 as 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 PHP documentation

  • So the main problem is that nothing is happening when you click on Ubmit, do the test yourself: www.madeireirapadroeira.com.br/novo-site and try to make a budget of anything, nothing arrives in my email and tbm nothing happens when you click on Ubmit

  • I’m sorry, I tried to describe the problem in a way but I couldn’t make you understand. I’ll take a look

  • Don’t get me wrong, it’s not a matter of "me" understanding friend, the question is "you" understand, you didn’t even mention the use of Ajax and jQuery, the code like this in the question doesn’t come close to being similar to the site, see how this failed to include jQuery: https://i.stack.Imgur.com/tFlmH.png

  • Thank you very much and I’m sorry also because I’m a beginner in the area, it’s been 1 month that I’m working in the area, so it happened these silly mistakes, I know they are silly because I program a little in C#. But in the web area for 1 month I have known. Well, I thank for the "bronca" kkkkkk now at least opened the file "mail.php". But I still need to know how you send the email because you have not yet sent the email but opened the mail.php file. You could help me.?

  • Yeah, I fixed it, I’ll put it on the air for you to take a look, okay?

  • ready, no problems on the console and files on air www.madeireirapadroeira.com.br/novo-site

  • Oops, yeah, I’m sorry, I forgot to fix this mistake... I just fixed and gave an error that is missing the class smtp.phpmailer.php and I’m putting it right now, Eraê...

  • @Joãorocha the mistake Function eregi() is deprecated I mean that you are using an old version of phpmailer, I recommend you update it.

  • I tried, man, but it didn’t work no :/

  • I just did that and still gave it this: This page is not working woodworking.com.br cannot meet this request at the moment.

  • I didn’t take it, I didn’t touch it, just the phpmailer

  • @Joãorocha sends the content of the mail.php in Pastebin.com to me please.

  • https://pastebin.com/GCBFEzAd

  • @Joãorocha be careful when typing in PHP, you are confusing apostrophes with quotes, this is the basics of php, variables within apostros do not access the variables: $mail->Subject = 'Contato pelo site - {$_POST['name']}".date("H:i")." - ".date("d/m/Y")';&#xA; $mail->Body = '$mensagem';&#xA; $mail->AltBody = '$mensagem';, corrected code: https://pastebin.com/raw/wF5GnFGM

  • Continue giving This page is not working lumberNailable.com.br cannot meet this request at this time. HTTP ERROR 500 I copied and pasted your code by only changing the password

  • @Joãorocha is sure he has uploaded the correct file to the server? On your localhost (wamp, xampp, easyphp or linux) the error occurs?

  • Yes, in localhost there is an error on line 37 - Parse error: syntax error, Unexpected 'name' (T_STRING) in C: wamp64 www Mad-Pad mail.php on line 37 and that’s what you get on line 37 - /$mail->Addaddress('[email protected]', 'Recipient Name'');

  • @Joãorocha your line 37 is different from line 37 of https://pastebin.com/raw/wF5GnFGM, copy and paste again please, you must have accidentally confused the files or edits. Test first on localhost

  • Sorry, I confused the boots kkkkkk, is giving error is on line 20 which is the line that is standardizing the classes - $mail = new Phpmailer;

  • @Did you copy "exactly" as I sent you the code? If the error is on line 20 could you send "what" error message now? Friend understand each error is a specific error say the "error" is in such place does not mean it will be part of the same error, understood?

  • Debugging... Fatal error: Call to Undefined method Phpmailer::From() in /home/madeirei/public_html/new-site/mail.php on line 32

  • This is what appears when http://madeireirapadroeira.com.br/novo-site/mail.php

  • @Joãorocha I said last time, please pay attention, I said I was to adapt "this" code: https://github.com/PHPMailer/PHPMailer#a-simple-example, the methods you used in your code are from the old version... I said I would have to redo with new version. Sorry for the sincerity, but please pay attention to tips ;) ... Correct, it’s not $mail->From('[email protected]');, the correct is $mail->setFrom('[email protected]');

  • All right, I’m sorry, it’s just that while I was here, I was changing the code over and over again by doing research and changing to do tests, and so I was giving every hour a mistake and every hour was a different code, forgive me, it was my mistake

  • @Joãorocha without problems ;) ... I am only guiding you and not giving scolding for evil, in programming you should pay attention to the details as much as possible and learn to analyze the mistakes. As soon as it’s over if you fail, let me know

  • Sorry for making you a little nervous kkkkk. Ahh and by the way, this came up : Debugging... Your fee§amento was sent to one of our attendants, please wait for the return soon. Probably sent it, but it hasn’t reached my inbox yet, so I think it’ll be here in a few minutes. I have no words to thank you for the help and for having lost a little time and a little patience cmg kkkk. Thanks for vdd!

  • I didn’t get nervous @Joãorocha, it’s just that you were messing up very unnecessarily, I needed to be firmer with you ;) ... Take a look at the Spam (or Mala_direct) box in the email, sometimes you may have dropped the message there.

  • Just dropped here, is it takes a while to send (2 mins in max), I think this is normal, is not?

  • @Joãorocha yes, has e-mail that can take up to an hour, depends on the flow of messages on the server. It has nothing to do with the PHP part, it’s something there in IMAP servers and transport SMTP, nothing we can do, depends on the same traffic, like "rush hour" on the avenues :)... I guess now all your problems have been solved right? I have to go, until next.

  • Until next time, William, thank you very much!

Show 25 more comments

0

In HTML I removed the remaining form

<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 errors.

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

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

more in if($_POST['name'] & $_POST[.... which has been corrected to if($_POST['name'] && $_POST[ ....

note also that I commented $mail->SMTPSecure = 'ssl'; and $mail->Port = 587; because these are not required on my server. I do not know if on your server are required. Ai vc do the appropriate tests with and without.

Follow the PHP 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;
    }
}?>
  • Thanks, that was one of the problems...

  • I got the e-mail, Leo.

Browser other questions tagged

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