0

I trying to send email using the PHP mail function but when I use fake email and it gives me no error and I cannot find out the email was sent or not I try all the ways from other similar question answers but I don't get what I want

I need to get a delivery report

my PHP version is 7.3

my PHP codes:

$to = 'example@somesite.com';

$subject = 'Message from ';

$message = $Message ;

$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

$headers[] = 'To: '. $to;
$headers[] = 'From: <sombody@theresite.com>';

if(mail($to, $subject, $message, implode("\r\n", $headers))){
    echo 555;
}else{
   echo 444;
}

Is there any way to get message for successful sent or fail?

Amir Hossein
  • 916
  • 2
  • 13
  • 38
  • From the [manual](https://www.php.net/manual/en/function.mail.php): "_Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise. It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination._" – brombeer Sep 25 '19 at 06:28
  • I need to get a delivery report, is that possible? – Amir Hossein Sep 25 '19 at 06:30

1 Answers1

0

For delivery confirmations:

You have to add the Disposition-Notification-To header.

For usage details see RFC 3798.

General tip for stuff like this:

Use the mail client of your choice to generate an e-mail with the desired parameters, send it to yourself and look at the mail source.

There you can find the necessary headers added by the feature you are looking for. Then read the RFC or google for specific details on the header in question.

Ref: Delivery reports and read receipts in PHP mail

Community
  • 1
  • 1
Bilal Ahmed
  • 119
  • 1
  • 11