Я использую общий план хостинга. Я пробовал свой уровень лучше, но я не могу решить эту проблему. вот мой код. Я сначала попробовал с gmail, но не работал, тогда я где-то читал, что IP-адрес моего общедоступного плана хостинга занесен в черный список google, после чего я устал от своего собственного smtp, а затем imap-сервера, то же самое получается, что он отлично работает на localhost, но снова я получаю то же самое ошибка.CodeIgniter почта не работает на сервере, но работает нормально localhost
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Contact extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
public function index()
{
$this->load->helper('security');
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
$this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('head');
$this->load->view('map');
$this->load->view('footer_map');
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to which you want to receive mails
$to_email = '[email protected]';
//configure email settings
$config['protocol'] = 'imap';
$config['smtp_host'] = 'imap.example.com';
$config['smtp_port'] = '587';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'example';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
// $this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->reply_to($from_email, $name);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contact/index');
}
else
{
//error
echo $this->email->print_debugger();
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contact/index');
}
}
}
public function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
я получаю этот выход
There is error in sending mail! Please try again later.
Помощь мне ребята, им усталого
Некоторые почтовые серверы в общих системах не позволят вам отправлять электронную почту, если адрес From не является адресом в этом домене. Поэтому, если вы являетесь веб-сайтом example.com, From должен быть [email protected] Попробуйте установить это и установите адрес электронной почты отправителя в качестве ответа на. – aynber