您好,我编写了以下代码,用于我使用 joomla 创建的网站的联系我们表单。表格显示在网站中 website link但我有两个问题 1.“消息部分”的标题落在文本框的底部而不是顶部 2. 我不是专业编码员,尤其是 PHP。当我输入并按下提交时,什么也没有发生。我假设我的 php 不工作。
<form id="contact-form" method="post">
<label for="name">اسم</label>
<input type="text" name="name" id="name" value=""/> <br>
<label for="email">ایمیل</label>
<input type="text" name="email" id="email" value="" /><br>
<label for="message">پیام</label>
<textarea name="message" id="message" cols="20" row="50" ></textarea> <br>
<input type="submit" name="submit" value="Submit" id="submit" />
</form>
<style type="text/css">
form
{
display: inline-block;
text-align: center;
font-family: "arial";
border:2px solid gray;
margin: 0px auto;
width: 900px;
height: 550px;
background: #580000;}
input
{
border: 1px solid black;
margin: 10px;
font-size: 15px;
}
textarea
{
border: 1px solid black;
margin: 10px;
font-size: 15px;
resize: none;
width: 200px;
height: 250px;
background: #fff;
}
#submit {
background-color: #000;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius:6px;
color: #000;
font-family: 'Oswald';
font-size: 15px;
text-decoration: none;
cursor: poiner;
border:none;
}
#submit:hover {
border: none;
background:grey;
box-shadow: 0px 0px 1px #777;
}
</style>
<?php
$ToEmail = 'evelina@jfaproduction.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
最佳答案
这是一个使用 Joomla 编码标准的模型。我只是以这种方式向您展示,因为您似乎非常热衷于坚持使用 Sourcerer。
HTML:
<form action="" id="contact-form" method="post">
<label for="name">اسم</label>
<input type="text" name="name" id="name" value=""/> <br>
<label for="email">ایمیل</label>
<input type="text" name="email" id="email" value="" /><br>
<label for="message">پیام</label>
<textarea name="message" id="message" cols="20" row="50" ></textarea> <br>
<input type="submit" name="submit" value="Submit" id="submit" />
</form>
PHP:
<?php
$mailer = JFactory::getMailer();
$input = JFactory::getApplication()->input;
$post = $input->post;
$submit = $post->get('submit');
if(isset($submit) {
$mailer->setSender($post->get('email'));
$mailer->addRecipient('evelina@jfaproduction.com');
$body = 'Name: ' . $post->get('name');
$body .= 'Email: ' . $post->get('email');
$body .= 'Message: ' . $post->get('message');
$mailer->setSubject('Site contact form');
$mailer->setBody($body);
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email';
}
else {
echo 'Success!';
}
}
?>
关于php - 我的联系表单 php 脚本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22871336/