Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i send an Email using PHP at windows Azure?

Tags:

How can i send an Email using PHP at windows Azure?

i am using simple mail function:

$to .= 'email-Id';
$subject = " Test Subject";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$to.'' . "\r\n";
$headers .= 'From: '.$name. '<'.$email.'>' . "\r\n";

echo $message='email text here';
@mail($to, $subject, $message, $headers);
like image 473
Amir Avatar asked May 14 '12 11:05

Amir


People also ask

Can you send email from PHP?

1. Using the PHP mail() function. PHP's built-in mail() function is one of the simplest ways to send emails directly from the web server itself. It just takes three mandatory parameters: the email address, email subject and message body—and sends it to the recipient.

Is PHP supported by Azure?

PHP is frequently used on Azure App Services (aka Microsoft Azure, Windows Azure, Azure Web Apps). Azure App Services manages pools of Windows Web Servers to host your web application, as an alternative to managing your own web server on your own Azure Compute VMs or other servers.


2 Answers

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('[email protected]')->
       setFrom('[email protected]')->
       setSubject('Subject goes here')->
       setText('Hello World!')->
       setHtml('<strong>Hello World!</strong>');
$sendgrid->smtp->send($mail);
like image 195
Sandrino Di Mattia Avatar answered Sep 17 '22 16:09

Sandrino Di Mattia


I had never done PHP, but the following guide was step by step and incredibly easy to get working.

http://www.windowsazure.com/en-us/Documentation/Articles/store-sendgrid-php-how-to-send-email/

Hope it helps someone.

like image 37
GR7 Avatar answered Sep 20 '22 16:09

GR7