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 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥15 MATLAB数据处理插值
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的
  • ¥15 硬件IIC从模式的数据发送,中断数据的接收,不能用HAL库(按照时序图)