如何在
Windows Azure中使用
PHP发送电子邮件?
- $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);
要使用PHP发送电子邮件,您有几个选择:
选项1:使用SMTP
您需要修改PHP.ini配置文件(http://php.net/manual/en/ref.mail.php),并将SMTP值设置为可以使用的外部SMTP服务器. SMTP服务器目前不是Windows Azure功能的一部分.
- [mail function]
- SMTP = mail.mycompany.com
选项二:使用sendmail
您需要修改PHP.ini配置文件(http://php.net/manual/en/ref.mail.php),并将sendmail_path值设置为sendmail可执行文件.
- [mail function]
- 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:
- $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);