我的控制器中有这个功能,用于向我正在构建的网站中的工作的广告商发送电子邮件;该函数可能看起来有点重载,但它基本上在做的是:
- 获取申请特定工作的人的详细信息,
- 工作的详细信息,以及
- 一份简历
所有这些信息都捆绑在一起,并在成功保存电子邮件的发送位置后发送到模型
public function sendapplication() {
if ($this -> request -> is('post')) {
$this -> JobApplication -> create();
$userid = CakeSession::read("UserAuth.User.id");
//this reads the current user id in the session established when the user logged in and uses it to store the job alert
$this -> JobApplication -> data['JobApplication']['user_id'] = $userid;
//$this -> JobApplication -> data['JobApplication']['job_post_id'] = $this -> JobApplication -> JobPost -> id;
$job_post_id = CakeSession::read('jobpost.id');//reading the job id session set above
$this -> JobApplication -> data['JobApplication']['job_post_id'] = $job_post_id;
$minorjobdetails = $this -> JobApplication -> sendapplicationmodel($job_post_id);
foreach ($minorjobdetails as $minorjobdetail) :
$this -> JobApplication -> data['JobApplication']['jobTitle'] = $minorjobdetail['JobPost']['jobTitle'];
$this -> JobApplication -> data['JobApplication']['employer'] = $minorjobdetail['JobPost']['contactName'];
endforeach;
$jobless = $this->JobApplication->JobPost->findById($job_post_id );
$job_applicant = $this->JobApplication->User->findById($userid);
$job_resume = $this -> request-> data['JobApplication']['resume_id'];
$attachedresume = current($this -> request-> data['JobApplication']['quickresume']);
$attachedresumepath = next($this -> request-> data['JobApplication']['quickresume']);
$attachedresumepath1 = next($this -> request-> data['JobApplication']['quickresume']);
$this -> log('Job resume id-' . $job_resume, LOG_DEBUG);
if ($this -> JobApplication -> save($this -> request -> data, false)) {
//$this->JobApplication->sendJobApplicationMail();
//$this -> Session -> setFlash(__('job application sent'));
$this->Session->setFlash('job application sent successfully', 'success', array('class' => 'alert alert-success'));
$this->JobApplication->sendJobApplicationMail($jobless, $job_applicant, $job_resume, $attachedresume, $attachedresumepath, $attachedresumepath1);
$this->JobApplication->deliveryReportEmail($job_applicant, $jobless);
$this -> redirect('/jobsposted');
} else {
$this -> Session -> setFlash(__('job application could not be sent. Please, try again.'));
}
}
}
有两个简历实例;用户可能在他/她申请工作之前已经上传到服务器或正在附加。我的问题是在表格上制作附件时出现。这是我的表格:
<?php
echo $this->Form->create('JobApplication', array('type' => 'file', 'enctype' =>'multipart/form-data', 'controller' => 'JobApplications', 'action' => 'sendapplication'));
foreach($jobseeker as $js):
echo $this->Form->input('fullname', array('class' => 'span6', 'value' => $js['User']['first_name']));
// debug($js['User']['first_name']);
echo $this->Form->input('lastname', array('class' => 'span6', 'value' => $js['User']['last_name'] ));
echo "<div class=\"input-prepend\">";
echo $this->Form->label('email');
echo "<span class=\"add-on\"><i class=\" icon-envelope\"></i></span>".$this->Form->input('email', array('class' => 'span6', 'value' => $js['User']['email'], 'label' => false, 'div' => false));
echo "</div>";
endforeach;
echo $this->Form->input('comment_application_letter',
array(
'type' => 'textarea',
'rows'=>10,
'cols' => 50,
'class' => 'span6',
'label' => 'Comment/ Application letter',
'placeholder' => 'E.g. My name is John Doe. I would like to apply for the marketing job position as posted on ABC company site on mm/dd/yyyy'
)
);
echo $this->Form->input('JobApplication.resume_id', array('label' => 'Select resume', 'type' => 'select', 'options' => $myResume));
// echo $this->Form->label($fieldName = 'selected-file', $text = 'Resume:');
// echo $this->Form->input('JobApplication.dropboxurl',array('type'=>'dropbox-chooser', 'name'=>'selected-file', 'id'=>'db-chooser', 'label' => false, 'visibilty' => 'hidden'));
echo $this->Form->input('JobApplication.quickresume', array('type' => 'file', 'label' => 'Attach resume'));
// echo $this->Form->input('', array('label' => 'Resume url', 'id' => 'dropboxurl', 'type' => 'text', 'div' => false, 'disabled', 'value' => '', 'class' => 'span6'));
echo "<br>";
echo $this->Form->button(__('Submit'),array('type' => 'submit', 'class' => 'btn btn-primary'))
?>
我想从表单中获取已附加的简历并将其与用户的详细信息一起发送;下面是模型中负责发送电子邮件的函数
public function sendJobApplicationMail($jobless, $job_applicant, $job_resume, $attachedresume, $attachedresumepath, $attachedresumepath1) {
// send email to newly created user
$userId = $jobless['JobPost']['id'];
$email = new CakeEmail();
$fromConfig = 'example@example.com';
$fromNameConfig = 'Jobs';
$email -> from(array($fromConfig => $fromNameConfig));
$email -> sender(array($fromConfig => $fromNameConfig));
$email -> to($jobless['JobPost']['jobapplicationEmail']);
$email -> subject(SITE_NAME . ': ' . __('Job Application'));
if(!empty($attachedresume)){
//file
pr($attachedresume);
pr($attachedresumepath);
pr($attachedresumepath1);
// pr($email->filePaths = array($attachedresumepath1));
// exit;
$email -> attachments(array('CV'=> $attachedresume));
//exit();
}
$email -> emailFormat('html');
$email -> template('applicant', 'fancy');
$email -> theme('Default');
$email -> viewVars(array('employer' => $jobless['JobPost']['contactName'], 'applicant_fname' => $job_applicant['User']['first_name'], 'applicant_sname' => $job_applicant['User']['last_name'], 'aplicant_email' => $job_applicant['User']['email']));
// $employer_contact_name = $jobless['JobPost']['contactName'];
// $job_applicant_fname = $job_applicant['User']['first_name'];
//$email->transport('Debug');
$body = __('Hi %s,<br/><br/>The below named person has shown interest on a job you posted;the details of the applicant are as follows: %s.<br/><br/>Thanks,<br/>%s', $jobless['JobPost']['contactName'], $job_applicant['User']['first_name'], SITE_NAME);
try {
$result = $email -> send($body);
$this -> log('Job apllication mail sent to job post id-' . $userId, LOG_DEBUG);
} catch (Exception $ex) {
// we could not send the email, ignore it
$result = "Could not send job application email to userid-" . $userId;
$this -> log($result, LOG_DEBUG);
}
}
我一直在尝试调试,这就是我尝试提交表单时得到的;
文件未找到: ””
错误:发生内部错误。
Stack Trace APP/Model/JobApplication.php 第 98 行 → CakeEmail->attachments(array) array('CV' => 'CAT 1 EvnCourseMay13.doc')
任何帮助将不胜感激。谢谢