微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何在 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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐