PHP Mail function does not work

Asked

Viewed 472 times

0

Hello, I have been trying to send an email through the PHP mail function, but nothing works, and after searching a little, I found a site that said it was necessary to have a fifth parameter, being the email that will receive the message, preceded by a -f, and it doesn’t work that way, here’s what I’ve got so far:

$dest = "[email protected]";
$nome = $_POST['nome'];
$email = $_POST['email'];
$assunto = $_POST['assunto'];
$header = "MIME-Version: 1.1 \r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1 \r\n";
$header .= "From: $email \r\n"; 
$header .= "Return-Path: $email \r\n";
$header .= "Reply-To: $dest \r\n"; 
$msg = $_POST['text'];

$mail = mail($dest, $assunto, $msg, $header, -f$dest);

And I have no idea what it might be, I’ve tried so much...

  • Use Phpmailer, you must inform the SMTP http://blog.thiagobelem.net/enviar-e-mails-pelo-php-usando-o-phpmailerconfiguration/

  • 2

    First of all, you need to set up the file php.ini with the parameters of your smtp server

  • 3

    You need to provide more details of your environment, is windows? is an external host or localhost?

  • @rray I’m sending from a windows using shaman(localhost).

  • 4
  • Try to last the sendgrid "https://sendgrid.com/", probably this your code is from some random template, and usually these functions in email sending php never work.

Show 1 more comment

1 answer

3

I use this way, and transforming into Base64 the email.

    $para="[email protected]";
    $assunto ="assunto Teste";
    $html="Olá esse é o conteudo do email";
    $headers = "From: Email do teste<[email protected]> \r\n";
    $headers .= "Reply-To:[email protected]\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    $headers.= "Content-Transfer-Encoding: base64\r\n";
    $headers .= rtrim(chunk_split(base64_encode($html)));

    $ok = mail($para , $assunto,'',$headers);
    echo $ok;

Browser other questions tagged

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