0 レビュー
1 回答
html-PHP mail()関数でメールを送信しない簡単な連絡フォーム
<脇>
答えへのリンク
この質問にはすでに回答があります:
わからない
0
レビュー
答え :
解決策:
これをテストしましたが、あなたが望むことをしていると思います。
$name = htmlentities($_POST['name']);
$email_from = htmlentities($_POST['email']);
$subject = htmlentities($_POST['subject']);
$message = htmlentities($_POST['message']);
$email_to = '[email protected]';//replace with your email
$headers = "From: [email protected]" . "\r\n" . "CC: ". $email_from; //This adds a from field, as well as CC's the person submitting the request.
//Build the body of the eamil
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email_from . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'message: ' . $message;
$success = mail($email_to, "Contact from site X, regarding: ".$subject, $body,$headers);
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<?php if($success){ //If the email was sent correctly?>
<script>
alert("Thank you for getting in touch. We will contact you as soon as possible.");
</script>
<?php header('Location: ../index.html'); }else{?>
<script>
alert("There was an error when sending the email, please try again later.");
</script>
<?php header('Location: ../index.html'); } //If the email falied?>
</head>
他のファイル(html)は同じままです。 php/send-contact.php
のコードをこれに置き換えるだけです。
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。