我在codeigniter中联系表格,但我不知道如何清除此错误?所以我试过?今天只有我正在使用codeigniter.can任何人帮助? 我收到了错误: 遇到PHP错误 严重性:注意 消息:使用未定义的常量“-contact_form” - 假设为“-contact_form” 文件名:controllers / contact.php 行号:33 IN应用程序控制器:
<?php
class contact extends ci_controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$mail_sent = false;
if ($this->input->post("q"))
{
// Loading email library of Codeigniter
$this->load->library(‘email’);
// Loading configuration file mail_config.php
$this->config->load(‘mail_config’,true);
// Setting email address and name of the person sending the email
$this->email->from($this->input->post("from"),$this->input->post("name"));
// Setting email address of the recipient
$this->email->to($this->config->item(‘to’,’mail_config’));
// Setting email subject
$this->email->subject($this->input->post("subject"));
// Setting email message body
$this->email->message($this->input->post("message",true));
// If mail sending successful
if ($this->email->send())
{
// If $mail_sent = true; it will show a success message.
$mail_sent = true;
}
}
$this->load->view(‘contact_form’,array(‘mail_sent’=>$mail_sent));
}
}
?>
在视图中:我创建了contact_form.php
<?php
if ($mail_sent):
?>
<b>Mail Sent</b>
<?php
endif;
?>
<form action="<?php echo base_url() ?>" method="POST">
<b>Your Name :</b>
<br />
<input type="text" name="name" value=""/>
<br />
<b>Your Email Address:</b>
<br />
<input type="text" name="from" value=""/>
<br />
<b>Subject :</b>
<br />
<input type="text" name="subject" value=""/>
<br />
<b>Message :</b>
<br />
<textarea name="message" rows="10" cols="15"></textarea>
<br />
<input type="submit" name="q" value="Contact" />
</form>
答案 0 :(得分:0)
您使用了错误的字符,将‘
替换为'
。