如何在Windows Azure中使用PHP发送电子邮件?

前端之家收集整理的这篇文章主要介绍了如何在Windows Azure中使用PHP发送电子邮件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在 Windows Azure中使用 PHP发送电子邮件

我使用简单的邮件功能

  1. $to .= 'email-Id';
  2. $subject = " Test Subject";
  3.  
  4. $headers = 'MIME-Version: 1.0' . "\r\n";
  5. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  6. $headers .= 'To: '.$to.'' . "\r\n";
  7. $headers .= 'From: '.$name. '<'.$email.'>' . "\r\n";
  8.  
  9. echo $message='email text here';
  10. @mail($to,$subject,$message,$headers);
要使用PHP发送电子邮件,您有几个选择:

选项1:使用SMTP

您需要修改PHP.ini配置文件(http://php.net/manual/en/ref.mail.php),并将SMTP值设置为可以使用的外部SMTP服务器. SMTP服务器目前不是Windows Azure功能的一部分.

  1. [mail function]
  2. SMTP = mail.mycompany.com

选项二:使用sendmail

您需要修改PHP.ini配置文件(http://php.net/manual/en/ref.mail.php),并将sendmail_path值设置为sendmail可执行文件.

  1. [mail function]
  2. sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

由于sendmail在Windows中不存在,因此您需要使用假的sendmail for Windows:http://glob.com.au/sendmail/

选项3:使用邮件/ smtp服务

您可以使用像SendGrid这样的服务发送您的电子邮件(他们有一个Azure用户的报价:http://sendgrid.com/azure.html).他们会照顾发送电子邮件,你只需要调用REST api:

  1. $sendgrid = new SendGrid('username','password');
  2. $mail = new SendGridMail();
  3. $mail->addTo('foo@bar.com')->
  4. setFrom('me@bar.com')->
  5. setSubject('Subject goes here')->
  6. setText('Hello World!')->
  7. setHtml('<strong>Hello World!</strong>');
  8. $sendgrid->smtp->send($mail);

猜你在找的Windows相关文章