加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 20:17:53 所属栏目:Windows 来源:网络整理
导读:如何在 Windows Azure中使用 PHP发送电子邮件? 我使用简单的邮件功能: $to .= 'email-Id';$subject = " Test Subject";$headers = 'MIME-Version: 1.0' . "rn";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";$headers .= 'To: '.
如何在 Windows Azure中使用 PHP发送电子邮件?

我使用简单的邮件功能:

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

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

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:wampsendmailsendmail.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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读