Bootstrap メールフォームの使用。フォームは、送信者の電子メール アドレスの代わりにサーバー名を表示する from 変数を除いて、メールを配信します。
$name 変数を「from」として表示する方法、または少なくとも、サーバー名ではなく電子メールの送信元のドメイン名を表示する方法を誰かが説明できますか?
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$business = $_POST['business'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From website of xxxxxx';
$to = 'user@somedomainname.com';
$subject = 'New Message ';
$body = "From: $name\n E-Mail: $email\n Business Name: $business\n Phone: $phone\nMessage: $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
// Check if business has been entered
if (!$_POST['business']) {
$errBusiness = 'Please enter your business or organization name';
}
// Check if phone has been entered
if (!$_POST['phone']) {
$errPhone = 'Please enter your phone number';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>