Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Contactus extends CI_Controller {
  5.  
  6. function __construct() {
  7. parent::__construct();
  8. $this->load->library('email');
  9. }
  10. public function index(){
  11. $this->load->helper('url');
  12.  
  13. $this->load->view('base');
  14. $this->load->view('contactUs');
  15. }
  16. public function send_mail(){
  17. //read parameters from $_POST using input class
  18. $name = $this->input->post('name');
  19. $email = $this->input->post('email');
  20. $subject = $this->input->post('subject');
  21. $message = $this->input->post('yourMessage');
  22.  
  23. $config = Array(
  24. 'protocol' => 'smtp',
  25. 'smtp_host' => 'your host',
  26. 'smtp_port' => port for host,
  27. 'smtp_user' => 'user@example.com',
  28. 'smtp_pass' => 'yourpassword',
  29. 'mailtype' => 'html',
  30. 'charset' => 'iso-8859-1',
  31. 'wordwrap' => TRUE
  32. );
  33. $this->load->library('email', $config);
  34.  
  35. $this->email->set_newline("rn");
  36.  
  37. $this->email->from($email, $name);
  38. $this->email->to('example@example.com');
  39.  
  40. $this->email->subject($subject);
  41. $this->email->message($message);
  42.  
  43. if ($this->email->send()){
  44. // mail sent
  45. $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
  46. redirect('contactus/send_mail');
  47. }else{
  48. //error
  49. $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
  50. redirect('contactus/index');
  51. }
  52. }
  53. }
  54.  
  55. <html>
  56. <head>
  57. <meta name="viewport" content="width=device-width, initial-scale=1">
  58. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  59. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  60. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  61. <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/contact.css">
  62. <title>Contact Us</title>
  63. </head>
  64. <body>
  65. <h1><center>Contact Us</center></h1>
  66. <hr>
  67. <div class="container">
  68. <div id="home-search">
  69. <form action= "<?php echo site_url("contactus/send_mail"); ?>" method='POST'>
  70. <div class="row">
  71. <div class="col-md-8 col-md-offset-2">
  72. <img src="http://oasissanjose.com/uploads/3/6/2/4/3624456/8429182_orig.png" class="pull-right" width="200" height="250">
  73.  
  74. <div class="panel panel-primary">
  75. <h2 class="lead section-lead panel-heading">Questions, Concerns? Contact us using the email template below:</h2>
  76. <h3 class="text-info panel-body"><center>All Fields are Mandatory</center></h3>
  77. <div class="form-all">
  78. <div class="form-group">
  79. <label for="name">Full Name<span class="form-required">*</span></label>
  80. <input type="text" class="form-control" id="name" name="name" placeholder="Jane Doe" required/>
  81. </div>
  82. <div class="form-group">
  83. <label for="email">Email Address<span class="form-required">*</span></label>
  84. <input type="email" class="form-control" id="email" name="email" placeholder="jane.doe@example.com" required/>
  85. </div>
  86. <div class="form-group">
  87. <label for="subject">Subject<span class="form-required">*</span></label>
  88. <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" required/>
  89. </div>
  90. <div class="form-group ">
  91. <label for="yourMessage">Your Message<span class="form-required">*</span></label>
  92. <textarea class="form-control" id="yourMessage" name="yourMessage" placeholder="Message" required></textarea>
  93. </div>
  94. <input type="submit" class="btn btn-primary" name="submit" value="Send Message" >
  95. <br>
  96. </div>
  97. </div>
  98. <br><br>
  99. <img src="http://content.presentermedia.com/files/animsp/00005000/5562/question_mark_serious_thinker_md_wm.gif" class="pull-right" width="400" height="250">
  100. </div>
  101. </div>
  102. </form>
  103. <?php echo $this->session->flashdata('msg'); ?>
  104. </div>
  105. </div>
  106. <!-- End of Container -->
  107. </body>
  108. </html>
  109.  
  110. smtp_server=smtp.gmail.com
  111. smtp_port=587
  112. smtp_ssl=tls
  113.  
  114. auth_username=your_email@gmail.com
  115. auth_password=password_of_email
  116.  
  117. force_sender=your_email@gmail.com
  118. hostname=smtp.gmail.com
  119.  
  120. $config = Array(
  121. 'protocol' => 'smtp',
  122. 'smtp_host' => 'ssl://smtp.googlemail.com',
  123. 'smtp_port' => 465,
  124. 'smtp_user' => 'xxx',
  125. 'smtp_pass' => 'xxx',
  126. 'mailtype' => 'html',
  127. 'charset' => 'iso-8859-1',
  128. 'wordwrap' => TRUE
  129. );
  130. $this->load->library('email', $config);
  131. $this->email->set_newline("rn");
  132.  
  133. // Set to, from, message, etc.
  134.  
  135. $result = $this->email->send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement