Error sending php form

Asked

Viewed 66 times

0

I am with a form that another programmer made and the emails from the site are no longer being sent, I can not find the error, also I am not very good with php. Someone can identify the mistake?

Follow the file mail.php, these checks at my view are correct in the function file, but by clicking send email is falling in the if "Infelizmente seus dados nao puderam ser enviados. Tente novamente mais tarde."

<?php

    require_once 'funcoes.php';

    //Determina o tipo da codificação da página
    header("content-type: text/html; charset=utf-8"); 

    //Extrai os dados do formulário
    extract($_GET); 

    $messageError = '';

    //Verifica se algum nome foi digitado
    if ($nome != "")
    {
        $name = utf8_decode($nome);
    }
    else
    {
        $messageError.='Insira seu Nome<br/>';
    }

    //Verifica se algum email foi digitado
    if ($email != "")
    {
        if(verificar_email($email) != 1)
        {
            $messageError.='Insira um E-mail válido<br/>';
        }
        else
        {
            $mail = utf8_decode($email);
        }

    }
    else
    {
        $messageError.='Insira seu E-mail<br/>';
    }

    //Verifica se algum telefone foi digitado
    $tel = ($telefone != "") ? $telefone : $messageError.='Insira seu Telefone<br/>';


    //Verifica se algum message foi digitado
    $message = ($mensagem != "") ? utf8_decode($mensagem) : $messageError.='URL Inválida<br/>';

    if ($valueContato == 1)
    {
        if ($estado == "")
            $messageError.='Insira um Estado<br/>';

        if ($cidade == "")
            $messageError.='Insira uma Cidade<br/>';
    }
    else
    if ($valueContato == 2)
    {       
        if ($preco == "")
        {
            $messageError.='Insira um Preço<br/>';
        }
    }

    if ($valueContato == "" or $valueContato == 2)
    {
        //Verifica se algum negocio foi digitado
        $business = ($negocio != "") ? utf8_decode($negocio) : $messageError.='Selecione um Negócio<br/>';

        //Verifica se algum url foi digitado
        if ($url != "")
        {
            if (!validarUrl($url))
            {
                $messageError.='URL inválida<br/>';
            }
            else
                $site = utf8_decode($url);  
        }
        else
            $messageError.='Insira um Endereço<br/>';
    }

    if ($messageError != "")
    {
        echo "$messageError";
        $messageError = '';
    }   
    else
    {
        $paraQuem = $valueContato;

        if ($paraQuem == "")
            $assunto = utf8_decode("Formulário Quero Comprar Domínio e Companhia");
        else
        if ($paraQuem == 1)
            $assunto = utf8_decode("Formulário de Contato Domínio e Companhia");
        else
            if ($paraQuem == 2)
            $assunto = utf8_decode("Formulário Quero Vender Domínio e Companhia");

        $estado = utf8_decode($estado);
        $cidade = utf8_decode($cidade);
        $para = '[email protected]';
        $assunto = $assunto;
        $corpo = "
            <html>
            <body>
                <p>$assunto</p>
                <p>
                    Nome:   <strong>$name</strong><br />
                    E-mail: <strong>$mail</strong><br />
                    Telefone: <strong>$tel</strong><br />";
        if($valueContato == 1)
            $corpo .= "Estado: <strong>$estado</strong><br />
                       Cidade: <strong>$cidade</strong><br />";
        else
        if($valueContato == 2)
            $corpo .= "Pre&ccedil;o: <strong>$preco</strong><br />";
        if ($valueContato == "" or $valueContato == 2)
            $corpo .="URL: <strong>$site</strong><br />
                      Neg&oacute;cio: <strong>$business</strong><br />";    
        $corpo .="
                    Mensagem:<strong>$message</strong><br />
                </p>
            </body>
            </html>";

        $headers = "From: {$nome} <{$email}> \nX-Mailer: PHP/" . phpversion()."\n";
        $headers .= "X-Sender: {$para}\n";
        $headers .= "X-Mailer: PHP\n";
        $headers .= "X-Priority: 1\n";
        $headers .= "Return-Path: {$email}\n";
        $headers .= "Content-Type: text/html; charset=iso-8859-1\n";

        // Mensagem resposta
        $sent = mail($para,$assunto,$corpo,$headers);


        if (!$sent) 
        {
            echo 'Infelizmente seus dados nao puderam ser enviados. Tente novamente mais tarde.';   
        }
        else 
        {
            echo 'Dados enviados com sucesso!';     
        }

    }   

?>
  • This happens on the localhost or production server?

  • on the production server.. ta online...

  • Before displaying the error message add this line print_r(error_get_last()); should give some details about the error.

  • will go in php.net, there is the use of the mail function, you will n need to write a lot and will be able to do virtually everything in email

  • Welcome to Stackoverflow. Just by looking at the code you may not be able to find out what the error is. You need to provide more details. Maybe there is some place where you can find a log or another way to view the error that has occurred in your application.

  • added the line but no error appears ..... I wanted to provide more details but I am not able to identify the error, I could not debug

  • 1

    Have you tried using the Phpmailer library with authenticated email ?

  • so I tried to user the phpmailer library, and now this appearing the following error, from the failure to send the message and appears SMTP server error: 5.7.0 Must Issue to STARTTLS command first

Show 3 more comments

1 answer

1

or it’s exchange or it’s imap or pop3 your email box. What is the domain of the box you are using? what you need to configure is SMTP for sending email. in case it is Gmail, smtp is configured like this :

Descrição SMTP Gmail: um nome generico (ex. "SMTP")
Nome do servidor SMTP Gmail: smtp.gmail.com
Usuario SMTP Gmail: o seu endereço Gmail
Password SMTP Gmail: a sua password
Porta SMTP Gmail: 465
  • 2

    For clarification use this field further below (comments), the larger space is unique to responses, the site works different from a forum to better understand the functioning recommend reading the [tour], if you have any questions just call @rray.

  • is Webmail the domain

  • I saw that you did not understand the negatives that led in the other answer, I believe the reason is the fact of having posted a 'comment' in the 'answer' space, I left a comment to the author of the question of how to get more details about the problem.

  • can find the error using phpmailer... SMTP server error: 5.7.0 Must Issue to STARTTLS command Firs

Browser other questions tagged

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