How can i send an Email using PHP at windows Azure?
To send emails using PHP you have a few options:
Option 1: Use SMTP
You'll need to modify your php.ini configuration file (http://php.net/manual/en/ref.mail.php) and set the SMTP value to an external SMTP server you can use. SMTP servers are not part of the Windows Azure features at the moment.
[mail function]
SMTP = mail.mycompany.com
Option 2: Use sendmail
You'll need to modify your php.ini configuration file (http://php.net/manual/en/ref.mail.php) and set the sendmail_path value to the sendmail executable.
[mail function]
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Since sendmail doesn't exist in Windows, you'll need to use the fake sendmail for windows: http://glob.com.au/sendmail/
Option 3: Use a mail/smtp service
You could use a service like SendGrid to send your emails (they have an offer for Azure users: http://sendgrid.com/azure.html). They'll take care of sending out the email, you'll just need to call the REST api:
$sendgrid = new SendGrid('username', 'password');
$mail = new SendGridMail();
$mail->addTo('foo@bar.com')->
setFrom('me@bar.com')->
setSubject('Subject goes here')->
setText('Hello World!')->
setHtml('<strong>Hello World!</strong>');
$sendgrid->smtp->send($mail);
How to receive emails via PHP contact form hosted on azure?
Azure Web Apps Service doesn't provide the STMP server and also we do not have permission to build one on it, so if you remove the @
, you may get the exception like: Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
.
To send mails from the PHP applications on Azure Web Apps, you can leverage some other 3rd part mail services like SendGrid.
You can easily create a SendGrid Account with Azure management portal. Please refer to https://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-php-how-to-send-email/ for details.
Any further concern, please feel free to let me know.
External SMTP setup on Azure
Actually, on Azure, you don't need to use External SMTP server to send emails in your app. You can easily use SendGrid to satisfy this.
Here is a detailed guide on how to use the SendGrid email service from PHP: https://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-php-how-to-send-email/.
How can I receive Email by using Windows Azure in my Website
The Windows Azure environment itself does not currently provide a SMTP relay or mail relay service. Steve Marx puts together a great sample application ( available for download here) that does the
following:
It uses a third party service (SendGrid) to send email from inside
Windows Azure.It uses a worker role with an input endpoint to listen for SMTP
traffic on port 25.It uses a custom domain name on a CDN endpoint to cache blobs.
here’s the code that handles an incoming email:
// make a container, with public access to blobs
var id = Guid.NewGuid().ToString().Replace("-", null);
var container = account.CreateCloudBlobClient().GetContainerReference(id);
container.Create();
container.SetPermissions(new BlobContainerPermissions() { PublicAccess=BlobContainerPublicAccessType.Blob });
// parse the message
var msg = new SharpMessage(new MemoryStream(Encoding.ASCII.GetBytes(message.Data)),
SharpDecodeOptions.AllowAttachments | SharpDecodeOptions.AllowHtml | SharpDecodeOptions.DecodeTnef);
// create a permalink-style name for the blob
var permalink = Regex.Replace(Regex.Replace(msg.Subject.ToLower(), @"[^a-z0-9]", "-"), "--+", "-").Trim('-');
if (string.IsNullOrEmpty(permalink))
{
// in case there's no subject
permalink = "message";
}
var bodyBlob = container.GetBlobReference(permalink);
// set the CDN to cache the object for 2 hours
bodyBlob.Properties.CacheControl = "max-age=7200";
// replaces references to attachments with the URL of where we'll put them
msg.SetUrlBase(Utility.GetCdnUrlForUri(bodyBlob.Uri) + "/[Name]");
// save each attachment in a blob, setting the appropriate content type
foreach (SharpAttachment attachment in msg.Attachments)
{
var blob = container.GetBlobReference(permalink + "/" + attachment.Name);
blob.Properties.ContentType = attachment.MimeTopLevelMediaType + "/" + attachment.MimeMediaSubType;
blob.Properties.CacheControl = "max-age=7200";
attachment.Stream.Position = 0;
blob.UploadFromStream(attachment.Stream);
}
// add the footer and save the body to the blob
SaveBody(msg, bodyBlob, message, container, permalink);
Related Topics
Which Is Fastest in PHP- MySQL or MySQLi
Format Output of $Simplexml->Asxml();
PHP Parsing Problem - &Nbsp; and Â
How to Disable Mod_Security in .Htaccess File
Bulk Rename Files in a Folder - PHP
Laravel Eloquent Sort by Relationship
Change Array Key Without Changing Order
Difference Between Set_Time_Limit() and Ini_Set('Max_Execution_Time', ...)
Answering Http_If_Modified_Since and Http_If_None_Match in PHP
How to Clear PHP's Gettext Cache Without Restart Apache Nor Change Domain