gpt4 book ai didi

javascript - 如何使联系表格提交对电子邮件的回复?

转载 作者:行者123 更新时间:2023-12-04 12:23:05 24 4
gpt4 key购买 nike

当用户点击 submit 时,我想制作联系表单以提交回复按钮。当用户点击 submit按钮,它还应该将它们重定向到 thankyou.html ,我已经完成了。但是回复也应该通过电子邮件发送给我。我被困在那部分,无法在 PHP 文件中弄清楚。
PHP 文件

$errors = '';
$myemail = 'm.hussainomer03@gmail.com'; // Put Your email address here.
if (empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message'])) {
$errors .= "\n Error: all fields are required";
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address)) {
$errors .= "\n Error: Invalid email address";
}

if (empty($errors)) {
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. " .
" Here are the details:\n Name: $name \n " .
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to, $email_subject, $email_body, $headers);

// Redirect to the 'thank you' page.
header('Location: contact-form-thank-you.html');
}
其余代码

input[type=text], [type=email], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}

input[type=submit] {
background-color: rgb(62, 3, 179);
color: white;
padding: 12px 20px;
border: none;
cursor: pointer;
}

input[type=submit]:hover {
background-color: deeppink;
}

.contactform {
position: relative;
border-radius: 50px;
background-color: #f2f2f2;
padding: 5px;
z-index: 2;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: auto;
margin-top: 1%;
width: 100%;
animation-name: gradient;
animation-duration: 3s;
animation-iteration-count: infinite;
}

.contactform:hover {
animation-name: gradient;
animation-duration: 15s;
animation-iteration-count: infinite;
}


.column {
float: center;
width: 50%;
margin-top: 6px;
padding: 20px;
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;

}

.row:after {
content: "";
display: table;
clear: both;
}

@media screen and (max-width: 600px) {
.column, input[type=submit] {
width: auto;
margin-top: 0;
}
}
<section id="contact">
<div class="container" data-aos="fade-up">
<div class="contactform">
<div style="text-align:center">
<div class="section-title">
<h2><br/>Get In Touch</h2>
</div>
<p>Feel Free To Reach Out To Me Through This Form! </p>
</div>
<div class="row">
<div class="column">
<form name="myform" action="contact.php" method="POST">
<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname" placeholder="Your name.." required>

<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" placeholder="Your last name.." required>

<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Your Email.." required>

<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="Lets Collaborate..." style="height:170px" required></textarea>
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
</div>
</section>

我试图重命名 php 中的类/对象之前的文件,但这也没有成功。

最佳答案

更改action="thankyou.html"action="yourMail.php"以便将表单 POST 数据发送到包含 mail() 的 php 文件功能不是你的thankyou.html。
另请注意,您需要一个 SMTP 服务器来从您的本地主机发送邮件。我会推荐你​​使用 PHPMailer。
HTML

<form name="myform" action="contact.php" method="POST">
<label for="name">First Name</label>
<input type="text" id="name" name="firstname" placeholder="Your name.." required>

<!-- <label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" placeholder="Your last name.." required> -->

<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Your Email.." required>

<label for="message">Subject</label>
<textarea id="message" name="message" placeholder="Lets Collaborate..." style="height:170px" required></textarea>
<input type="submit" value="Submit">
</form>

关于javascript - 如何使联系表格提交对电子邮件的回复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66036859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com