gpt4 book ai didi

php - 如何使用联系表格 php

转载 作者:可可西里 更新时间:2023-11-01 00:58:32 25 4
gpt4 key购买 nike

我从 theme forest 买了一个主题,用 html 和 css 进一步构建它。但是有一个联系表格,我不知道如何使用。我是 php 和 javascript 的初学者。我认为我应该将我的电子邮件地址插入到://在此处输入您的电子邮件地址 $address = 'hello@email.com';。但这并没有锻炼。

我的问题是:我该如何进行这项工作,以便当有人试图通过填写联系表与我联系时,我会收到邮件到我的电子邮件地址。我在我的本地服务器上自己测试过,当我试图填写联系表格时我没有收到任何邮件。任何人请带我到正确的方向。

<?php

if(!$_POST) exit;

function tommus_email_validate($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email); }

$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$comments = $_POST['comments'];

if(trim($name) == '') {
exit('<div class="alert danger">Attention! You must enter your name.</div>');
} else if(trim($name) == 'Name') {
exit('<div class="alert danger">Attention! You must enter your name.</div>');
} else if(trim($email) == '') {
exit('<div class="alert danger">Attention! Please enter a valid email address.</div>');
} else if(!tommus_email_validate($email)) {
exit('<div class="alert danger">Attention! You have entered an invalid e-mail address.</div>');
} else if(trim($website) == 'Website') {
exit('<div class="alert danger">Attention! Please enter your website.</div>');
} else if(trim($website) == '') {
exit('<div class="alert danger">Attention! Please enter your website.</div>');
} else if(trim($comments) == 'Message') {
exit('<div class="alert danger">Attention! Please enter your message.</div>');
} else if(trim($comments) == '') {
exit('<div class="alert danger">Attention! Please enter your message.</div>');
} else if( strpos($comments, 'href') !== false ) {
exit('<div class="alert danger">Attention! Please leave links as plain text.</div>');
} else if( strpos($comments, '[url') !== false ) {
exit('<div class="alert danger">Attention! Please leave links as plain text.</div>');
} if(get_magic_quotes_gpc()) { $comments = stripslashes($comments); }

//ENTER YOUR EMAIL ADDRESS HERE
$address = 'hello@email.com';

$e_subject = 'You\'ve been contacted by ' . $name . '.';
$e_body = "You have been contacted by $name from $website from your contact form, their additional message is as follows." . "\r\n" . "\r\n";
$e_content = "\"$comments\"" . "\r\n" . "\r\n";
$e_reply = "You can contact $name via email, $email";

$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );

$headers = "From: $address" . "\r\n";
$headers .= "Reply-To: $email" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=utf-8" . "\r\n";
$headers .= "Content-Transfer-Encoding: quoted-printable" . "\r\n";

if(mail($address, $e_subject, $msg, $headers)) {
echo "<fieldset><div id='success_page'><h4 class='remove-bottom'>Email Sent Successfully.</h4><p>Thank you <strong>$name</strong>, your message has been submitted to us.</p></div></fieldset>";
}
<section id="contact" class="page-section dark-wrapper">
<div class="container">
<div class="row">

<div class="page-header text-center">
<!-- multiple h1's are perfectly acceptable on a page in valid HTML5, when wrapped in individual sections, they're 100% semantically correct -->
<h1>Contact Me<small>Here's a Working Contact Form</small></h1>
<!-- seriously -->
</div>

<div class="col-sm-8">
<div id="message"></div>
<form method="post" action="sendemail.php" id="contactform">
<input type="text" name="name" id="name" placeholder="Name" />
<input type="text" name="email" id="email" placeholder="Email" />
<input type="text" name="website" id="website" placeholder="Website" />
<textarea name="comments" id="comments" placeholder="Comments"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
</div>

<div class="col-sm-4 lp30">
<h5>Contact Me</h5>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar.</p>
<ul class="fa-ul">
<li class="bm15"><i class="fa fa-map-marker fa-fw fa-2x fa-li"></i> Denmark</li>
<li class="bm15"><i class="fa fa-phone-square fa-fw fa-2x fa-li"></i> 08044576869</li>
<li class="bm15"><i class="fa fa-laptop fa-fw fa-2x fa-li"></i> <a href="mailto:info@jjtranslation.com" target="_top">mail@me.com</a></li>
</ul>
</div>

</div>
</div>
</section>

最佳答案

如果您不想为编写 PHP 代码而烦恼,请查看 Formspree .该服务每月最多 1000 个请求是免费的。

它的使用也非常简单:只需将 action 属性添加到您的表单中。像这样:

<form action="//formspree.io/your@email.com"
method="POST">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
</form>

关于php - 如何使用联系表格 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34305653/

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