1

I have got this simple php mail function

$to = "munucom@mail.ru";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: munucom@mail.ru" . "\r\n" .
"CC: munucom@mail.ru";
if(mail($to,$subject,$txt,$headers)){
  echo "done";  
}

It echos done but when i check my email there is nothing.Even in spam section

lIP TT
  • 77
  • 1
  • 6

1 Answers1

0

Use PHPMailer library.It is better than use mail native function because in PHPMailer you can use user authentication to avoid to send the email to spam.You can use this library without to configure a mail server.It's more easiest to debug. You can download in this link https://github.com/PHPMailer/PHPMailer

See an example:

$mail             = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "tls";                 
$mail->Host       = "smtp.gmail.com";      // SMTP server
$mail->Port       = 587;                   // SMTP port
$mail->Username   = "yourusername@gmail.com";  // username
$mail->Password   = "yourpassword";            // password

$mail->SetFrom('user@gmail.com', 'Test');

$mail->Subject    = "I hope this works!";

$mail->MsgHTML('Blah');

$address = "test@test.com";
$mail->AddAddress($address, "Test");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
msantos
  • 691
  • 5
  • 6