[英]HTML Form won't send email on submit
I've developed an iOS app and rails backend server. 我已经开发了一个iOS应用程序和Rails后端服务器。 While I took some HTML classes back in university, it's been a long while since I've touched any.
我上大学时上过一些HTML课,但距离接触任何东西已有很长时间了。
I purchased a 'template' website to be my application landing page. 我购买了一个“模板”网站作为我的应用程序登录页面。 I've tweaked it to be what I want, but I'm having 1 issue with the Contact/Form Submission page.
我已经对其进行了调整,但“联系方式/表单提交”页面出现1个问题。 When I press send, I do not receive an email at the intended email address.
当我按发送时,我不会在预期的电子邮件地址收到电子邮件。 I'm not sure if this is an issue with the code (I'm guessing not, I would think this highly rated template would have had something like this correct), or if I need to set up something with my domain that I currently haven't done as I wouldn't know about it.
我不确定这是否与代码有关(我想不是,我想这个高度评价的模板应该有这样的正确名称),或者我是否需要使用我当前的网域设置一些内容还没有做,因为我不知道。
Here's the relevant code... 这是相关的代码...
index.html 的index.html
<form action="javascript:;" method="post">
...
<input type="submit" class="button white" value="Send →" />
</form>
send_email.php send_email.php
<?php
// Replace this with your own email address
$to="example@gmail.com";
// Extract form contents
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Validate email address
function valid_email($str) {
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
// Return errors if present
$errors = "";
if($name =='') { $errors .= "name,"; }
if(valid_email($email)==FALSE) { $errors .= "email,"; }
if($message =='') { $errors .= "message,"; }
// Send email
if($errors =='') {
$headers = 'From: FluidApp <no-reply@fluidapp.com>'. "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$email_subject = "Website Contact Form: $email";
$message="Name: $name \n\nEmail: $email \n\nWebsite: $website \n\nSubject: $subject \n\nMessage:\n\n $message";
mail($to, $email_subject, $message, $headers);
echo "true";
} else {
echo $errors;
}
?>
However, nothing is being sent to my email "example@gmail.com". 但是,没有任何内容发送到我的电子邮件“ example@gmail.com”。
What might I be missing here? 我在这里可能会缺少什么?
Maybe replace 也许取代
<form action="javascript:;" method="post">
with 同
<form action="send_email.php" method="post">
That should do it, assuming the ...
in your HTML snippet contains the right variables for the form submission- name
, email
, website
, subject
, message
, etc. 假设HTML代码段中的
...
包含表单提交name
, email
, website
, subject
, message
等正确的变量,应该可以做到这一点。
EDIT: OP figured it out. 编辑: OP弄清楚了。
Place the <form action="send_email.php" method="post">
放置
<form action="send_email.php" method="post">
and remove <form action="javascript:;" method="post">
并删除
<form action="javascript:;" method="post">
<form action="javascript:;" method="post">
it will work perfect your send_email.php is good 它将完美工作您的send_email.php是好的
place all 2 files in same folder 将所有2个文件放在同一文件夹中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.