Tôi đã thiết lập bộ điều khiển và biểu mẫu liên hệ của tôi đã được thiết lập. Nhưng khi tôi nhấp vào "Gửi" trên trang liên hệ của tôi, tôi không nhận được lỗi nhưng tôi không nhận được email. Bất cứ ai có thể giúp tôi tìm ra lý do tại sao tôi không thực sự nhận được email? Tôi đánh giá cao sự giúp đỡ nào. Đây là mã của tôi cho bộ điều khiển:Làm cách nào để gửi email thành công trong biểu mẫu liên hệ qua CodeIgniter?
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->template->build('home');
}
public function email() {
$name = $this->input->post('name');
$email = $this->input->post('email');
$phone_number = $this->input->post('phone_number');
$message = $this->input->post('message');
$this->load->library('email');
$this->email->from($email, 'Your Name');
$this->email->to('[email protected]');
$this->email->cc('[email protected]');
$this->email->bcc('[email protected]');
$this->email->subject('Email Test');
$this->email->message(
'My name is'.$name.', Im testing this email class. My email is '.$email. '. My Phone number is '.$phone_number.
' This is my message '.$message. ' Thanks!!'
);
$this->email->send();
echo $this->email->print_debugger();
$this->template->build('home');
}
}
Và đây là mã của tôi để xem trang liên lạc của tôi:
<div class="inner-content" id="contact-content">
<title>CSS3 Contact Form</title>
<div id="contact">
<h1>Send an email</h1>
<form method="post" action="/home/email">
<fieldset>
<label for="name">Name:</label>
<input name="name" id="name" type="text" placeholder="Enter your full name">
<label for="email">Email:</label>
<input name="email" id="email" type="email" placeholder="Enter your email address">
<label for="message">Message:</label>
<textarea name="message" id="message" placeholder="Type your message here..."></textarea>
<input type="submit" value="Send message">
</fieldset>
</form>
</div>
</div>
Trước tiên, hãy đảm bảo bạn đã thiết lập máy chủ SMTP để gửi email chính xác. –
Trình gỡ lỗi lặp lại điều gì? –
Đầu ra là chính xác này: Thông điệp của bạn đã được gửi thành công bằng cách sử dụng giao thức sau: mail From: "Your Name" Return-Path: Cc: [email protected] Bcc: họ @ their- example.com Trả lời: "[email protected]" X-Người gửi: [email protected] X-Mailer: CodeIgniter X-Mức độ ưu tiên: 3 (Bình thường) ID thư: <51b0de09bea00 @ gd. com> Phiên bản Mime: 1.0 Loại nội dung: văn bản/đồng bằng; charset = utf-8 Content-Transfer-Encoding: 8bit =? utf-8? Q? Email_Test? = Tên tôi isdfdfdf, Im đang kiểm tra lớp email này. Email của tôi là [email protected] Số điện thoại của tôi là Đây là thông điệp của tôi dfdfdfdfdfsdafsafsdfsfdsfdsfsdf Cảm ơn !! –