如何在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);
Run Code Online (Sandbox Code Playgroud)
San*_*tia 18
要使用PHP发送电子邮件,您有以下几种选择:
选项1:使用SMTP
您需要修改php.ini配置文件(http://php.net/manual/en/ref.mail.php)并将SMTP值设置为可以使用的外部 SMTP服务器.SMTP服务器目前不是Windows Azure功能的一部分.
[mail function]
SMTP = mail.mycompany.com
Run Code Online (Sandbox Code Playgroud)
选项2:使用sendmail
您需要修改php.ini配置文件(http://php.net/manual/en/ref.mail.php)并将sendmail_path值设置为sendmail可执行文件.
[mail function]
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Run Code Online (Sandbox Code Playgroud)
由于Windows中不存在sendmail,因此您需要将伪造的sendmail用于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);
Run Code Online (Sandbox Code Playgroud)
我从来没有做过PHP,但是下面的指南是一步一步的,非常容易上班.
http://www.windowsazure.com/en-us/Documentation/Articles/store-sendgrid-php-how-to-send-email/
希望它可以帮助某人.
归档时间: |
|
查看次数: |
19029 次 |
最近记录: |