我创建了一个电子邮件实用程序,它显示了从中接收电子邮件的电子邮件 ID 的主题行和日期。每个电子邮件 ID 旁边都有一个复选框。无论单击哪个复选框,电子邮件都会发送到该电子邮件 ID。我的问题是我想在同一页面上显示“消息发送成功”或错误消息而无需重新加载。
我认为,使用 ajax 是可能的,但我不知道如何。这是我的看法:
<?php echo form_open_multipart('accessmail/sendmail'); ?>
<div>
//here I display my emails
<div>
<div class="table_wrap1">
<div>Subject:</div>
<div><input type="text" required="required" id="subject" name="subject"></div>
</div>
<div class="table_wrap1">
<div>Email:</div>
<div><input type="email" id="replyto" name="replyto"></div>
</div>
<div id="txteditor">
<textarea name="textarea">
</textarea>
<button name="submit" value="process" type="submit">Send</button>
</div>
<?php } ?>
</div>
</form>
我的控制器名称是“accessmail”,方法名称是“发送邮件”:
public function sendmail()
{
$this->load->library('email');
$count=$this->input->post('mailcount');
$subject = $this->input->post('subject');
$msg = $this->input->post('textarea');
$replyto = $this->input->post('replyto');
//variable for checking whether any email id is selected or not
$status=0;
//for sending email to checked email id's
for($i=0;$i<$count;$i++)
{
// check whether the checkbox for a particular email id is checked or not
if(!$this->input->post('emailid'.$i))
{
continue;
}
else
{
//set the values for this email and send it
$this->email->from('abc@abc.com', 'abc');
$this->email->subject($subject);
$this->email->message($msg);
$idtosend = $this->input->post('emailid'.$i);
$this->email->to($idtosend);
if ($this->email->send())
{
$status++;
}
}
}
//for sending email to email id provide in textbox
if(!empty($replyto))
{
$this->email->from('abc@abc.com', 'Abc');
$this->email->subject($subject);
$this->email->message($msg);
$this->email->to($replyto);
if ($this->email->send())
{
$status++;
}
}
if($status>0)
{
//this message should be displayed on the same page along with other contents of the page
echo "Your message has been sent";
}
if($status==0)
{
//this message should be displayed on the same page along with other contents of the page
echo "Select any Email-id first";
}
}
我的问题是成功消息应该显示在保留页面内容的同一视图上。提前致谢。