Microsoft Azure Webserver --> PHP mail() Function

Daniel Bäuerlein 1 Reputation point


i use a microsoft azure webspace for hosting my php files.
I wonder why the standard mail() function does not work:

$messagetext = "Message line 1\r\nMessage line 2\r\nMessage line 3";

if (mail('', 'mySubject', $messagetext)) {
echo "Email was sent";
} else {
echo "Email was NOT sent"; //unfortunately, message is not sent

On webspace of my old webprovider ( this function worked perfectly.

Thank you for support.

Best wishes


Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,505 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 16,621 Reputation points Microsoft Employee

    @Daniel Bäuerlein Thanks for reaching out. You cannot send a mail using mail() function since SMTP connections on TCP port 25 is blocked in Azure and it is suggested to use either SendGrid or Logic apps.

    • This guide demonstrates how to perform common programming tasks with the SendGrid email service on Azure. The samples are written in PHP. The scenarios covered include constructing email, sending email, and adding attachments.
    • Refer to this documentation steps, if you want to send emails with Gmail from your App Service app by using Azure Logic Apps.

    Recommended method of sending email from Azure VM or from Azure App service.
    For more information, refer to this blog post on How to send email on App service using Office 365

    Feel free to reach back to me if you have further queries on this.

    0 comments No comments