0

I want to send a email from php mail function. This is my code

<?php
  $to = "modiv2301@gmail.com";
  $subject = "HTML email";

  $message = "
       <h1>this is msg</h1>
  ";


  $headers = "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

  $headers .= 'From: <modiv2301@gmail.com>' . "\r\n";
  $success=mail($to,$subject,$message,$headers);
  if (!$success) {
      $errorMessage = error_get_last()['message'];
      print_r($errorMessage);
  }else{
      echo "Success";
      $errorMessage = error_get_last()['message'];
      print_r($errorMessage);
  }
  ?>

when i run this code its showing me Success but i am not Receiving any email

vivek modi
  • 800
  • 2
  • 7
  • 23
  • I think gmail will reject your sender, because it's not authenticated to GMail, but claims to be a gmail sender. You could try to change the sender or try to send to another email account. – evayly Jun 09 '18 at 08:57
  • i had changed sender and receiver both mail but problem is still there – vivek modi Jun 09 '18 at 09:03
  • Possible duplicate of [How do I prevent mails sent through PHP mail() from going to spam?](https://stackoverflow.com/questions/5935087/how-do-i-prevent-mails-sent-through-php-mail-from-going-to-spam) – Tewdyn Jun 09 '18 at 09:05
  • Can you send mail from the command line on that system? The `mail()` function relies on the systems mailing logic to be setup correctly. Check your systems log files for issues too. – arkascha Jun 09 '18 at 09:06
  • its not showing my mail even in my spam box – vivek modi Jun 09 '18 at 09:06
  • Use a class like PHPMailer. It takes care of your basic headers for you. Easy to use install and use. https://github.com/PHPMailer/PHPMailer – Joseph_J Jun 09 '18 at 09:08

0 Answers0