我的网站上有一个联系表单,它连接到Mailgun服务器,可以在提交时发送电子邮件。
本地一切都很好,但当在Heroku上托管时,表单并没有按预期运行,而是触发了下载。知道需要做些什么才能让它正常运行吗?
我曾尝试将我的index.html
设置为index.php
,并将PHP脚本放在页面顶部的<?php ?>
标记中——这两种方法都可以在本地使用——但在Heroku上都不起作用。
谢谢!
表单来自index.html:
<form method="post" name="contact_form" action="form.php">
<h1>want to chat?</h1>
<input type="text" name="name" placeholder="name" required>
<input type="email" name="email" placeholder="email" required>
<textarea name="message" cols="30" rows="10" placeholder="drop a message..." required></textarea>
<input type="submit" value="send off" name="submit">
<h1 class="email-thanks"></h1>
</form>
form.php文件:
<?php
require '../vendor/autoload.php';
use Mailgun'Mailgun;
session_start();
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
# Instantiate the client.
$mgClient = new Mailgun('key-xxxxxxxx');
$domain = "mail.laurenfazah.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => $name . ' <' . $email . '>',
'to' => 'Lauren <example@gmail.com>',
'subject' => 'Portfolio Message',
'text' => $message
));
}
header( 'Location: /' ) ;
session_destroy();
?>
听起来它所在的服务器没有安装PHP。