[英]HTML Form won't send email on submit
我已經開發了一個iOS應用程序和Rails后端服務器。 我上大學時上過一些HTML課,但距離接觸任何東西已有很長時間了。
我購買了一個“模板”網站作為我的應用程序登錄頁面。 我已經對其進行了調整,但“聯系方式/表單提交”頁面出現1個問題。 當我按發送時,我不會在預期的電子郵件地址收到電子郵件。 我不確定這是否與代碼有關(我想不是,我想這個高度評價的模板應該有這樣的正確名稱),或者我是否需要使用我當前的網域設置一些內容還沒有做,因為我不知道。
這是相關的代碼...
的index.html
<form action="javascript:;" method="post">
...
<input type="submit" class="button white" value="Send →" />
</form>
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;
}
?>
但是,沒有任何內容發送到我的電子郵件“ example@gmail.com”。
我在這里可能會缺少什么?
也許取代
<form action="javascript:;" method="post">
同
<form action="send_email.php" method="post">
假設HTML代碼段中的...
包含表單提交name
, email
, website
, subject
, message
等正確的變量,應該可以做到這一點。
編輯: OP弄清楚了。
放置<form action="send_email.php" method="post">
並刪除<form action="javascript:;" method="post">
<form action="javascript:;" method="post">
它將完美工作您的send_email.php是好的
將所有2個文件放在同一文件夾中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.