如何通过 CodeIgniter 成功发送联系表单中的电子邮件?

2024-02-27

我已经设置了我的控制器和我的联系表。但是,当我在联系页面上单击“提交”时,我没有收到任何错误,但没有收到电子邮件。谁能帮我弄清楚为什么我实际上没有收到电子邮件?我很感激任何帮助。这是我的控制器代码:

<?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] /cdn-cgi/l/email-protection');
        $this->email->cc('[email protected] /cdn-cgi/l/email-protection');
        $this->email->bcc('[email protected] /cdn-cgi/l/email-protection');
        $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');
    }
}

这是我的联系页面视图的代码:

<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>

enable php_openssl.dll in php.ini文件并尝试使用 Gmail。帕斯卡·斯普雷特(Pascal Spruit)或奥马德(Omade)的答案将会起作用。编辑后不要忘记重新启动本地服务器php.ini file.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过 CodeIgniter 成功发送联系表单中的电子邮件? 的相关文章

随机推荐