我正在使用谷歌应用引擎制作一个HTML网站。我的index.html中有一个联系表单,它调用send_mail.php发送电子邮件。问题是当我点击发送它要求我下载PHP。有没有办法来解决这个问题。这是我的app.yaml文件
application: engineapp
version: 1
runtime: php
api_version: 1
handlers:
- url: /
static_files: assets/index.html
upload: assets/index.html
- url: /
static_dir: assets
我的html文件的代码是普通的联系表单
<form class="form" id="form1" action="send_mail.php" method="post">
<p>
<input name="name" type="text" id="name" />
</p>
<p>
<input name="email" type="text" id="email" />
</p>
<p>
<input name="email" type="text" id="sub" />
</p>
<p>
<textarea name="text" id="comments" placeholder="الرسالة"></textarea>
</p>
<input type="submit" value="ارسل" id="button-pink"/>
</font>
</form>
我的php文件看起来像这样
<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "xyz@hotmail.com";
/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$index = "index.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";
/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$name = $_REQUEST ['name']
$email_address = $_REQUEST['email'] ;
$sub = $_REQUEST ['sub']
$comments = $_REQUEST['comments'] ;
/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email_address'])) {
header( "Location: $index" );
}
// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($comments)) {
header( "Location: $error_page" );
}
// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}
// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email", "Contact Form", "Subject: $sub",
$comments, "From: $email_address" );
header( "Location: $thankyou_page" );
}
?>
答案 0 :(得分:0)
您需要send_mail.php
的网址处理程序,例如:
- url: /(.+\.php)$
script: assets/\1
这适用于所有somefile.php
脚本。或者,硬编码这个脚本,如:
- url: /send_mail.php
script: assets/send_mail.php