Sending Email on Server

Asked

Viewed 24 times

0

I’m trying to create a page that sends emails but I’m not receiving them...

Would you have something you should check ?

Follow code I use to send...

<?php
$message = "Testando outros remetentes, para facilitar a resposta";
$headers = 'From: [email protected]';

if (mail('[email protected]', 'Teste', $message, $headers)) {
    print('Funcionou');
}else{ 
    print('Nao Funcionou...');
};
?>

This FROM email must be registered on my server in the hosting panel or I can use a generic one ?

  • It’s sending from a local server?

  • @Miguel Não, from a paid Hosting server

1 answer

1

Try so, the problem are often the default headers, should set them, mainly the From and the Reply-To

$body = 'corpo da mensagem';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "From: Miguel <[email protected]>" . "\r\n" .
"Reply-To: [email protected]" . "\r\n" .
"X-Mailer: PHP/" . phpversion();

if(!mail('[email protected]', 'teste', $body, $headers)) 
{
    echo 'Erro';
}
else {
    echo 'YAY';
}
  • Thanks for the support ! However the "Error" message is displayed, would know what might be occurring ?

  • Write print_r(error_get_last()); before the echo 'Erro'; and see what you print

  • No message is displayed... only Error

  • Type this at the beginning of the file and try again: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); . Serves to see php errors

  • Nothing... I believe it can be the port, as I define a port in PHP mail ?

  • See if this helps: http://stackoverflow.com/questions/23793716/how-to-set-port-and-host-for-php-function-mail

Show 1 more comment

Browser other questions tagged

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