PHP mail function

Asked

Viewed 125 times

0

I am trying to use the php mail function to send the information of a form to my email. I’ve been through a lot of pits, but I can’t make it work. What’s wrong with you?

  • Don’t give any kind of error or notice, just don’t send anything, just go back to index as if you had sent.
  • The Site is already hosted because I know it does not work local;

obs. the message to be sent I haven’t edited yet. But it still doesn’t send anything to span.

    <?php

include('conexao.php');
    $envia = new conexao;
    $envia->conecta();

/* Verifica qual é o sistema operacional do servidor para ajustar o cabeçalho de forma correta. Não alterar */
if(PHP_OS == "Linux") $quebra_linha = "\n"; //Se for Linux
elseif(PHP_OS == "WINNT") $quebra_linha = "\r\n"; // Se for Windows
else die("Este script nao esta preparado para funcionar com o sistema operacional de seu servidor");


    $emaildestinatario = "meu email";
    $assunto = "Contrato pelo site";

// Passando os dados obtidos pelo formulário para as variáveis abaixo
    $razaosocial        = $_POST['txtRazaosocial'];
    $nomefantasia       = $_POST['txtNomefantasia'];
    $cnjp               = $_POST['txtCnpj'];
    $insce              = $_POST['txtIe'];
    $end                = $_POST['txtEndereco'];
    $numero             = $_POST['txtNumero'];
    $complemento        = $_POST['txtComp'];
    $bairro             = $_POST['txtBairro'];
    $cep                = $_POST['txtCep'];
    $cidade             = $_POST['txtCidade'];
    $estado             = $_POST['txtUf'];
    $email              = $_POST['txtEmail'];
    $telefone           = $_POST['txtTel'];
    $contato            = $_POST['txtContato'];
    $sistema            = $_POST['txtSistema'];
    $usuarios           = $_POST['txtQtdadeusu'];
    $data_envio         = date('d/m/Y');
    $hora_envio         = date('H:i:s');


/* Montando a mensagem a ser enviada no corpo do e-mail. */
$mensagemHTML = '<P>Esse email &eacute; um teste enviado no formato HTML via PHP mail();!</P>';


/* Montando o cabeçalho da mensagem */
$headers = "MIME-Version: 1.1".$quebra_linha;
$headers .= "Content-type: text/html; charset=iso-8859-1".$quebra_linha;
// Perceba que a linha acima contém "text/html", sem essa linha, a mensagem não chegará formatada.
$headers .= "From: ".$email.$quebra_linha;
$headers .= "Return-Path: " . $email . $quebra_linha;

/* Enviando a mensagem */
mail($emaildestinatario, $assunto, $mensagemHTML, $headers, "-r". $email);


header("Location: index.php");

?>
  • Please rephrase the question so that we understand it better. What has already been tried, which desktop you are using, which error/notice is displayed.

  • Are you trying to use it on a localhost test server or production server? if it’s on-premises, you need to install an SMTP server on the local machine to run or set up an smtp in php.ini, if it’s in production, see hosting support.

  • It will redirect anyway, either true or false, because you did not check the return of the mail function. Just try: mail('[email protected]', 'Subject', 'message'); without variables in a separate file.

  • Mauro, not even so the way you said send, I made a new file and put in the form, but did not send.

  • What is your server?

  • Your settings in PHP.ini are correct ?

  • On my server it gives the same thing, but it takes about 1 day for e-mail to arrive. Is it not happening the same with you ?

  • The settings are correct because I have another form working, what I took as base. And unfortunately not this coming even, the envoy yesterday did not arrive until the time.

Show 3 more comments

1 answer

0


I managed to make it work people. Thank you all. The problem was in the form, which gap rs was without the tag name.

Browser other questions tagged

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