Microsoft Azure Webserver --> PHP mail() Function

Daniel Bäuerlein 1 Reputation point
2022-07-03T08:05:15.317+00:00

Hi,

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('my@emailadress.de', 'mySubject', $messagetext)) {
echo "Email was sent";
} else {
echo "Email was NOT sent"; //unfortunately, message is not sent
}

On webspace of my old webprovider (all-inkl.com) this function worked perfectly.

Thank you for support.

Best wishes

Daniel

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

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 19,646 Reputation points Microsoft Employee
    2022-07-04T10:17:06.137+00:00

    @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