dourong6054 2016-03-23 19:52
浏览 28
已采纳

如何通过托管在azure上的PHP联系表单接收电子邮件? [关闭]

I'm not receiving emails from my contact form on my website and not sure how to fix this? The website is hosted on Microsoft Azure. How would I go about resolving this?

The code I currently have is:

<?php
if (isset($_POST['contact_name']) && isset($_POST['contact_email']) 
&& isset($_POST['contact_text'])) {
$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$contact_text = $_POST['contact_text'];
if(!empty($contact_name) && !empty($contact_email) && !empty($contact_text)) {

    $to = 'email@domain.com';
    $subject = 'Message from website.';
    $body = $contact_name."
".$contact_text;
    $headers = 'From: ' .$contact_email;

    if(@mail('email@domain.com', $contact_text, $body, $headers)) {
        echo 'Thank you';
    } else {
        echo 'error.';
    }
}
else {
    echo 'You're missing something';
     }
   }
  ?>

<form action="" method="POST">
    Name: <input type="text" name="contact_name">
    Email: <input type="text" name="contact_email">
Message: <textarea name="contact_text" rows="5" cols="20"></textarea>
<input type="submit" value="Send">

</form>

Thank you.

  • 写回答

1条回答 默认 最新

  • dongpangbu4016 2016-03-24 02:24
    关注

    Azure Web Apps Service doesn't provide the STMP server and also we do not have permission to build one on it, so if you remove the @, you may get the exception like: Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set().

    To send mails from the PHP applications on Azure Web Apps, you can leverage some other 3rd part mail services like SendGrid.

    You can easily create a SendGrid Account with Azure management portal. Please refer to https://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-php-how-to-send-email/ for details.

    Any further concern, please feel free to let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里