Scroll to top

Haloo! Selamat Datang di Komunitas Private Training Web Development (34895 Members, 309 Projects, 3065 Topic, 8573 Comments)

Butuh karyawan baru? atau seorang Web Developer (Part-time/Freelance/Full-time) untuk mengerjakan project/aplikasi anda?, cari disini : Members Area Jobs!
Membuat form kontak email dengan Codeigniter di Localhost
Alex Makasighe Mengatakan : Members -
  1. saya mengalami kendala membuat form kontak email dari localhost..
  2. apa ada setingan lain untuk servernya..
  3. atau ada yang salah dengan script ini
  4.  
  5. <?php
  6. class Contactform extends CI_Controller
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->helper(array('form','url'));
  12. $this->load->library(array('session', 'form_validation', 'email'));
  13. }
  14.  
  15. function index()
  16. {
  17. //set validation rules
  18. $this->form_validation->set_rules('name', 'Name', 'trim|required|callback_alpha_space_only');
  19. $this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
  20. $this->form_validation->set_rules('subject', 'Subject', 'trim|required');
  21. $this->form_validation->set_rules('message', 'Message', 'trim|required');
  22.  
  23. //run validation on form input
  24. if ($this->form_validation->run() == FALSE)
  25. {
  26. //validation fails
  27. $this->load->view('front/contact_form_view');
  28. }
  29. else
  30. {
  31. //get the form data
  32. $name = $this->input->post('name');
  33. $from_email = $this->input->post('email');
  34. $subject = $this->input->post('subject');
  35. $message = $this->input->post('message');
  36.  
  37. //set to_email id to which you want to receive mails
  38. $to_email = 'alexmakasighe2@gmail.com';
  39.  
  40. //configure email settings
  41. $config['protocol'] = 'smtp';
  42. $config['smtp_host'] = 'smtp.googlemail.com';
  43. $config['smtp_port'] = '465';
  44. $config['smtp_user'] = 'alexmakasighe2';
  45. $config['smtp_pass'] = '';
  46. $config['mailtype'] = 'html';
  47. $config['charset'] = 'iso-8859-1';
  48. $config['wordwrap'] = TRUE;
  49. $config['newline'] = "\r\n"; //use double quotes
  50. $this->load->library('email', $config);
  51. $this->email->initialize($config);
  52.  
  53. //send mail
  54. $this->email->from($from_email, $name);
  55. $this->email->to($to_email);
  56. $this->email->subject($subject);
  57. $this->email->message($message);
  58. if ($this->email->send())
  59. {
  60. // mail sent
  61. $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
  62. redirect('contactform/index');
  63. }
  64. else
  65. {
  66. //error
  67. $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
  68. redirect('contactform/index');
  69. }
  70. }
  71. }
  72.  
  73. //custom validation function to accept only alphabets and space input
  74. function alpha_space_only($str)
  75. {
  76. if (!preg_match("/^[a-zA-Z ]+$/",$str))
  77. {
  78. $this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
  79. return FALSE;
  80. }
  81. else
  82. {
  83. return TRUE;
  84. }
  85. }
  86. }
  87. ?>
Robby Prihandaya Mengatakan :
Admin -
  1. Assalam, Scriptnya saya cek sepertinya tidak ada masalah mas,..
  2. pesan errornya apa mas,..?
  3. atau coba aktifkan juga baris berikut di xampp/php/php.ini :
  4.  
  5. ;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
  6. ubah menjadi
  7. sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Nasir Mahmud Ahmad Mengatakan :
Members -
  1. Salam,
  2. Saya jg mengalami hal yg sama namun tidak ada pesan error.
  3. Saya install di server cpanel.
  4. Saat sya trial send pesan via contact form lalu sya cek ke email tidak ada email masuk.
  5. Kira2 masalahnya dmn ya?
  6.  
  7. Trims, salam

Maaf, Untuk Memberikan Komentar Anda Harus Login !!!