0

I use the Internet Information Services(IIS) with PHP. But the mail() function doesn't seem to be working. At first I tried to fix the php.ini. Then I downloaded hMailServer. Now it shows "Your message has been sent!" but I haven't got any messages in my inbox. I also checked the SPAM inbox. But I can't find anything.

<?php 

    error_reporting(-1);
    ini_set('display_errors', 'On');
    set_error_handler("var_dump");
    $name = $_POST['name'];
    $email = "yunishuseynzade1102@gmail.com";
    $message = "Hello how are you?";
    $from = 'dj.yunis.official@gmail.com'; 
    $to = 'yunishuseynzade1102@gmail.com'; 
    $subject = 'Customer Inquiry';
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    if (mail($to, $subject, $body, $from)) { 
        echo '<p>Your message has been sent!</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    }


?>
BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91

2 Answers2

0

Your 4 Parameter($from) is wrong because it expects an string with header information. you only post a email into it. cange your $from to:

$from = 'From: dj.yunis.official@gmail.com';
BlackNetworkBit
  • 768
  • 11
  • 21
  • I changed it but don't works.Writes "Message Sent!" but i can not find it on my inbox. – YunisHuseynzade Aug 31 '19 at 12:20
  • @YunisHuseynzade You cannot send mail to gmail addresses from other Gmail addresses if you use your own mail server. Use a mail address hosted on the IIS – Ferrybig Sep 10 '19 at 06:07
0

Configure SMTP E-Mail in IIS:

  • open iis manager.
  • Features View, double-click SMTP E-mail.
  • On the SMTP E-mail page, type the e-mail address of the sender in the E-mail address text box.
  • On the SMTP E-mail page, select any delivery method.
  • Deliver e-mail to SMTP server: enter image description here
  • If Store e-mail in pickup directory is selected, type the batch e-mail location in the Store e-mail in pickup directory text box.
  • Click Apply in the Actions pane.

set below setting in the php.ini file:

[mail function]
SMTP=localhost
sendmail_from = string
smtp_port=25

Update:

You need to check your junk mail folder.

Below is my working example:

my mail send code:

enter image description here

enter image description here

enter image description here

enter image description here

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26