我从主题森林购买了一个主题,用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>
答案 0 :(得分:2)
如果您不想打扰编写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>
答案 1 :(得分:1)
您可以对此进行测试,但您必须在php.ini中正确配置SMTP服务器。如果你在托管服务器上进行测试,那应该不是问题,如果你正在测试localy,你必须编辑你的php.ini文件并设置SMTP服务器。
答案 2 :(得分:1)
如果没有正确配置php.ini,您将永远不会在本地发送任何电子邮件(您需要设置正确的smtp服务器)。但是,当您将其上传到您的虚拟主机位置时,它将开始工作,没有任何电子邮件混淆。它将使用来自服务器的smtp设置。只要尝试上传,你就会看到那种魔力。