0

I am trying to send emails from PHP code, the emails are not sending out. I have checked port 25 and it doesn't looked blocked from the server side

I am hosting my Site on Windows Server 2019 and using IIS I have found this code to test the PHP mail function and I am getting Error Msg

<?PHP
$sender = '****@e-****.co.za';
$recipient = '****@e-*****.co.za';

$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers))
{
    echo "Message accepted";
}
else
{
    echo "Error: Message not accepted";
}
?>

Error: Message not accepted

I have PHP Version 7.2.26 installed and it is working correctly

How else can I check what would be blocking SMTP messages being sent

eTrack
  • 7
  • 3
  • Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – ADyson Aug 10 '21 at 13:56
  • I have gone thru most of them. I am using phpmailer to send, the problem I have is when I upgraded my software it just refuses to send mails. Was working fine before this so not sure if the phpmailer is refusing to send the mail. but even on a basic test as above it not sending mail out – eTrack Aug 10 '21 at 14:09
  • `when I upgraded my software`...what _exactly_ did you upgrade? And if you have done all the things on that list I provided then you should have more detail to be able to give us about the problem because you should have some details from error logs to show us. – ADyson Aug 10 '21 at 14:10
  • P.S. Have you definitely installed the SMTP server onto your Windows server, and configured it? – ADyson Aug 10 '21 at 14:11
  • I have not installed SMTP server as we did not use it before. The software upgrade is a platform using IIS. It uses phpmailer according to the developer and according to them it is not the software/platform but IIS. Maybe I should try installing SMTP server and see from there – eTrack Aug 10 '21 at 14:34
  • 1
    So, how do you expect to be able to send mail without an SMTP service? mail() needs a local mailserver to connect to and send the emails for it. All mail() does is pass the details of the email to the mailserver. It's the mailserver's job to actually send it to the destination. Your code, without a mailserver, is the equivalent of leaving a parcel on your doorstep and hoping it will be collected, instead of taking it to the post office. – ADyson Aug 10 '21 at 14:37
  • 1
    `It uses phpmailer according to the developer`...well the code you've shown us above does not use PHPMailer. N.b. PHPMailer, if you were to use it, has the capability to connect to an SMTP server on another machine and send the email from there, but mail() does not – ADyson Aug 10 '21 at 14:37

0 Answers0