我对PHP非常非常陌生,我仍在努力学习。但我现在有一个问题需要立即解决,所以我正在寻求任何帮助。
我正在尝试制作一个可以通过电子邮件发送信息的联系表格。
这是我的html:
<form method="POST" action="?" >
<div id="header2">
<p id="heading">CONTACT ME</p>
<p> Send your inquiries or comments here and I'll get back to you right away.</p>
</div>
<label for="name">Your Name </label>
<input type="text" name="name" placeholder="Juan Dela Cruz" width="100px;">
<label for="email"> Email Address </label>
<input type="text" name="email" placeholder="yourname@email.com">
<label for="contact"> Contact Number </label>
<input type="text" name="contact" placeholder="Mobile or Landline">
<label for="message"> Message </label>
<textarea type="text" name="message" rows="10" cols="25" placeholder="Your Message"></textarea>
<input type="submit" value="Send Message" id="submit">
<input type="reset" value="Reset Fields" id="reset">
<p id="feedback"> <?php echo $feedback; ?> </p>
<div id="socialcontact">
<h4> CJSS </h4>
<p> Address
</p>
<a href="#"> <img src="images/fb-2.png" alt="Find me on Facebook"/> </a> <a href="#"> <img alt="Follow me on Twitter" src="images/twitter-2.png" /> <a href="#"> <img alt="Connect with me on Linked In" src="images/linkedin-2.png" /> <a href="#"> <img alt="Check me out on Behance" src="images/behance-2.png" />
</div>
</form>
现在是我的php:
<?php
$to = 'myemail@gmail.com';
$subject = 'An inquiry from your website';
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$body = $_POST['message'];
$message = <<<EMAIL
$name
$email
$contact
$message
EMAIL;
$header = "From: $email";
if($_POST){
if($name == '' || $email == '' || $message == ''){
$feedback = 'Kindly fill our all the (*)necessary fields';
}else{ mail($to, $subject, $body, $header);
$feedback = 'Thank you, email sent. I will get back to you as soon as I can.';}
}
?>
我把这个php放在一切之上。
当我通过测试服务器预览它时,它会显示错误消息:
(!)注意:未定义的索引:第8行C:''wamp''www''projectlevity4''contact.php中的电子邮件调用堆栈
时间记忆功能位置
1 0.0007 258368{main}()。。''contact.php:0
(!)注意:第9行C:''wamp''www''projectlevity4''contact.php中的未定义索引:contact调用堆栈
时间记忆功能位置
1 0.0007 258368{main}()。。''contact.php:0
(!)注意:第10行C:''wamp''www''projectlevity4''contact.php中的未定义索引:message调用堆栈
时间记忆功能位置
1 0.0007 258368{main}()。。''contact.php:0
(!)注意:未定义的变量:第19行C:''wamp''www''projectlevity4''contact.php中的message调用堆栈
时间记忆功能位置
1 0.0007 258368{main}()。。''contact.php:0
我该怎么办才能解决这个问题?我正努力赶在最后期限前完成任务,希望你能帮我。
感谢
在HTML:中
<input type="submit" value="Send Message" id="submit" name="submit">
在PHP中:
if(isset($_POST['submit'])){
// your code
}