我已经按照在线教程创建了带有附件形式的发送电子邮件。表单本身正在工作,但是当我使用发送按钮发送表单时,它只给出不存在的错误页面。我确信它与路线有关,但我似乎找不到更多关于它的信息。想知道是否有人会知道这可能是什么?
Sendemail.php -Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sendemail extends CI_Controller {
public function index()
{
$this->load->view('sendemail');
}
public function send()
{
$subject = 'Student ID Confirmation - ' . $this->input->post("name");
$file_data = $this->upload_file();
if(is_array($file_data))
{
$message = '
<h3 align="center">Student Details</h3>
<table border="1" width="100%" cellpadding="5">
<tr>
<td width="30%">Name</td>
<td width="70%">'.$this->input->post("name").'</td>
</tr>
<tr>
<td width="30%">Student ID</td>
<td width="70%">'.$this->input->post("studentid").'</td>
</tr>
<tr>
<td width="30%">Address</td>
<td width="70%">'.$this->input->post("address").'</td>
</tr>
<tr>
<td width="30%">Email Address</td>
<td width="70%">'.$this->input->post("email").'</td>
</tr>
<tr>
<td width="30%">Student Course</td>
<td width="70%">'.$programming_languages.'</td>
</tr>
<tr>
<td width="30%">Experience Year</td>
<td width="70%">'.$this->input->post("experience").'</td>
</tr>
<tr>
<td width="30%">Phone Number</td>
<td width="70%">'.$this->input->post("mobile").'</td>
</tr>
<tr>
<td width="30%">Additional Information</td>
<td width="70%">'.$this->input->post("additional_information").'</td>
</tr>
</table>
';
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtpout.secureserver.net',
'smtp_port' => 80,
'smtp_user' => 'xxxxxxxxxx',
'smtp_pass' => 'xxxxxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
//$file_path = 'uploads/' . $file_name;
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($this->input->post("email"));
$this->email->to('16060409@stu.mmu.ac.uk');
$this->email->subject($subject);
$this->email->message($message);
$this->email->attach($file_data['full_path']);
if($this->email->send())
{
if(delete_files($file_data['file_path']))
{
$this->session->set_flashdata('message', 'Application Sended');
redirect('sendemail');
}
}
else
{
if(delete_files($file_data['file_path']))
{
$this->session->set_flashdata('message', 'There is an error in email send');
redirect('sendemail');
}
}
}
else
{
$this->session->set_flashdata('message', 'There is an error in attach file');
redirect('sendemail');
}
}
function upload_file()
{
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'doc|docx|pdf|jpeg|jpg|png|';
$this->load->library('upload', $config);
if($this->upload->do_upload('resume'))
{
return $this->upload->data();
}
else
{
return $this->upload->display_errors();
}
}
}
?>
sendemail.php ---视图
<!DOCTYPE html>
<html>
<head>
<title>How to Send an Email with Attachment in Codeigniter</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br />
<div class="container">
<div class="row">
<div class="col-md-8" style="margin:0 auto; float:none;">
<h3 align="center">Send Student ID Details to gain access</h3>
<br />
<?php
if($this->session->flashdata("message"))
{
echo "
<div class='alert alert-success'>
".$this->session->flashdata("message")."
</div>
";
}
?>
<h4 align="center">Required Information</h4>
<br />
<form method="post" action="<?php echo base_url(); ?>sendemail/send" enctype="multipart/form-data">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Enter Full Name</label>
<input type="text" name="name" placeholder="Enter Name" class="form-control" required />
</div>
<div class="form-group">
<label>Enter Student ID</label>
<input type="text" name="name" placeholder="Enter Student ID" class="form-control" required />
</div>
<div class="form-group">
<label>Enter Email Address</label>
<input type="email" name="email" class="form-control" placeholder="Enter Email Address" required />
</div>
<div class="form-group">
<label>Select Programming Language</label>
<select name="programming_languages[]" class="form-control" multiple required style="height:150px;">
<option value="Computing">BSc Computing</option>
<option value="CS">Computer Science</option>
<option value="CGDev">Computer Games Development</option>
<option value="CAVE">Computer Animation/Visual Effects</option>
<option value="SE">Software Engineeting</option>
<option value="CFS">Computer Forensics/Security</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Select Year of Course</label>
<select name="experience" class="form-control" required>
<option value="">Select Year</option>
<option value="1 year">1st Year</option>
<option value="2 year">2nd Year</option>
<option value="3 year">Final Year</option>
<option value="4 year">Placement Year</option>
</select>
</div>
<div class="form-group">
<label>Enter Mobile Number</label>
<input type="text" name="mobile" placeholder="Enter Mobile Number" class="form-control" pattern="\d*" />
</div>
<div class="form-group">
<label>Select Your Resume</label>
<input type="file" name="resume" accept=".doc,.docx, .pdf" required />
</div>
<div class="form-group">
<label>Enter Additional Information</label>
<textarea name="additional_information" placeholder="Enter Additional Information" class="form-control" required rows="8"></textarea>
</div>
</div>
</div>
<div class="form-group" align="center">
<input type="submit" name="submit" value="Submit" class="btn btn-info" />
</div>
</form>
</div>
</div>
</div>
</body>
</html>
路线
$route['default_controller'] = 'User';
$route['account'] = 'user/account';
$route['Sendemail'] = 'user/Sendemail';
$route['send'] = 'send/Sendemail';
感谢您的帮助。