locked
sending mail through php RRS feed

  • Question

  • the following code is not working for me

    $to = $email; 
    $subject = "Microsoft Developer Group";
    $message = "Thank you for registering with us..";
    $from = "xyz@gmail.com";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);

    please help me in this. i am not able to send mail through php


    sushant sagar

    Wednesday, October 22, 2014 3:20 PM

Answers

  • Hi,

    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);

    Also, you can refer this link for more details.

    http://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-php-how-to-send-email/#bkmk_UsingSendGridfromPHP

    Hope this helps you to send emails.

    Girish Prajwal

    • Marked as answer by sushant sagar Monday, November 3, 2014 8:16 AM
    Monday, November 3, 2014 7:35 AM

All replies

  • Hey there, can you please tell me more about your problem?  This doesn't appear related to Azure SQL Database and I'd like to get your question to the right place.
    Wednesday, October 22, 2014 3:56 PM
  • I have my site hosted and linked with a database on SQL server on azure.

    I used to write this code for sending mails through php for mysql server but it is not working on SQL server on azure.

    This is the right place for this question I guess because this code is not working only for SQl server on azure.


    sushant sagar

    Wednesday, October 22, 2014 4:01 PM
  • Hi,

    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);

    Also, you can refer this link for more details.

    http://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-php-how-to-send-email/#bkmk_UsingSendGridfromPHP

    Hope this helps you to send emails.

    Girish Prajwal

    • Marked as answer by sushant sagar Monday, November 3, 2014 8:16 AM
    Monday, November 3, 2014 7:35 AM
  • this solution is perfectly fine but now I am facing another problem. that is I cant start the SendGrid service.

    every time I try starting it I get an error of which a screenshot is attached. I even contacted Microsoft azure support team but they were not able to solve the issue.

    well, can you please throw some more light on option 2 because that seems to be a good option for me.


    sushant sagar

    Monday, November 3, 2014 8:24 AM