0
我有一個聯繫表格(聯繫表格=購物車),其中用戶可以上傳文件附件和一切正常,除了沒有附件發送到郵件..我得到「你沒有選擇要上傳的文件。「Codeigniter電子郵件文件附加不工作
我的觀點:
<?php
$order_cart_form_attr = array('class' => 'ui equal width form', 'id' => 'order_cart_form', 'enctype' => 'multipart/form-data');
echo form_open_multipart('Kassa/send_cart', $order_cart_form_attr);
?>
<div class="fields">
<div class="field ui left icon input">
<input type="text" class="required-group" name="order_firstname" id="order_firstname" placeholder="Имя">
<i class="user icon"></i>
</div>
<div class="field ui left icon input">
<input type="text" name="order_lastname" id="order_lastname" placeholder="Фамилия">
<i class="user icon"></i>
</div>
</div>
<div class="fields">
<div class="field ui left icon input">
<input type="text" class="required-group" name="order_email" id="order_email" placeholder="Email">
<i class="mail icon"></i>
</div>
<div class="field ui left icon input">
<input type="text" class="required-group" name="order_phone" id="order_phone" placeholder="Телефон">
<i class="phone icon"></i>
</div>
</div>
<br><br>
<div class="fields">
<div class="field ui left icon input">
<input type="text" class="required-group" name="order_inn" id="order_inn" placeholder="ИНН">
<i class="suitcase icon"></i>
</div>
<div class="field ui left icon input">
<input type="file" name="order_file" id="order_file" />
<i class="cloud upload icon"></i>
</div>
</div>
<br><br>
<div class="field">
<textarea class="required-group" name="order_comment" id="order_comment" placeholder="Комментарий к заказу"></textarea>
</div>
<button id="order_cart_submit_btn" class="ui fluid vertical animated button" tabindex="0">
<div class="hidden content"> <i class="shop icon"></i> </div>
<div class="visible content">
Послать заявку
</div>
</button>
<div id="contactFormResponseMSG"></div>
<?php echo form_close(); ?>
控制器:
public function send_cart() {
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'UTF-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$order_firstname = $this->input->post('order_firstname', TRUE);
$order_lastname = $this->input->post('order_lastname', TRUE);
$order_email = $this->input->post('order_email', TRUE);
$order_phone = $this->input->post('order_phone', TRUE);
$order_comment = $this->input->post('order_comment', TRUE);
$order_inn = $this->input->post('order_inn', TRUE);
$order_file = $this->input->post('order_file', TRUE);
$order_CartTotal = $this->cart->format_number($this->cart->total());
foreach ($this->cart->contents() as $items):
$order_CartInfo = $this->input->post('order_NameDiametr', TRUE);
$order_NameDiametr = $items['name'].' | '.$items['options']['diametr']. "<br>";
endforeach;
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
if (! $this->upload->do_upload('order_file')) {
$error = array('error' => $this->upload->display_errors());
print_r($error);
print_r($this->upload->data());
}
else {
$this->upload->do_upload('order_file');
}
$this->form_validation->set_rules('order_firstname', 'Order_lastname', 'required|trim');
$this->form_validation->set_rules('order_lastname', 'Order_lastname', 'trim');
$this->form_validation->set_rules('order_email', 'Order_email', 'valid_email|trim');
$this->form_validation->set_rules('order_phone', 'Order_phone', 'required|trim');
if ($this->form_validation->run() == FALSE) {
print "<div class='ui negative message'>";
\t print validation_errors();
print "</div>";
}
else {
$this->email->set_newline("\r\n"); \t
$this->email->from('---', '---');
$this->email->to('---');
$this->email->subject('---');
$body = "Имя: ".$order_firstname . "<br>";
$body .= "Фамилия: ".$order_lastname . "<br>";
$body .= "Телефон: ".$order_phone . "<br>";
$body .= "ИНН: ".$order_inn . "<br>";
$body .= "File: ".$this->email->attach($order_file) . "<br>";
$body .= "Email: ".$order_email . "<br><br>";
$body .= "Комментарий к заказу: ".$order_comment. "<br><br>";
foreach ($this->cart->contents() as $items):
$body .= $items['name'].' | '.$items['options']['diametr']. "<br><br>";
endforeach;
$body .= "Итого: ".$order_CartTotal." руб";
$this->email->message($body);
$this->email->attach($order_file);
$this->email->send();
}
莫非取決於someth在ajax調用?
$(document).on("click", "#order_cart_submit_btn", function (e) {
\t
$("#order_cart_form").validate({
rules: {
order_firstname: "required",
order_lastname: {
required: false
\t \t },
order_email: {
required: false,
email: true
\t \t },
\t \t order_phone: {
required: true,
digits: true
\t \t },
\t \t order_comment: {
required: true
\t \t }
},
messages: {
\t order_firstname: {
required: "Ваше имя"
},
order_lastname: {
required: "Ваша фамилия"
},
order_phone: {
required: "Ваш номер",
digits: "Ваш номер"
\t /* minlength: jQuery.validator.format("Minst 8 siffror."),
\t maxlength: jQuery.validator.format("Max 15 siffror.")*/
},
order_email: {
required: "Ваш email",
\t email: "Ваш email"
},
order_comment: {
//required: "Комментарий к заказу"
required: ""
},
\t \t /*order_message: {
required: "Vänligen skriv ett meddelande"
},*/
},
errorClass: 'error-view',
validClass: 'success-view',
errorElement: 'span',
debug: true,
\t
\t submitHandler: function(form) {
e.preventDefault();
\t
\t $.ajax({
url: "Kassa/send_cart",
\t type: "POST",
\t data: $('#order_cart_form').serialize(),
cache: false,
\t
\t \t beforeSend: function(data, xhr, status) {
\t console.log(data); \t
},
\t
\t \t success: function(data, xhr, status) {
\t \t if (data.status == 'fail') {
console.log("FAIL ALERT");
$("#contactFormResponseMSG").html('<div class="ui negative message">Ваша заявка не была отправлена. <br> Попробуйте еще раз позже.</div>');
$('#contactUsForm').form('clear');
}
else {
$("#contactFormResponseMSG").html('<div id="order_cart_form_success_msg" class="ui positive message">Спасибо. <br> Ваша заявка была успешно отправлена. Мы свяжемся с Вами в ближайшее время.</div>');
$('#order_cart_form').form('clear');
}
}
});
return false;
form.submit();
}
});
\t \t \t
});
好的。但我使用codeigniter 3 ..我也沒有任何「包括」 - 文件夾 – opps521
我在System/Libraries/Email.php中找到該行,並將其更改爲您所建議的內容..沒有成功。 – opps521
我更新了我的答案,請做第二招,並給我舉報。 –