如何通过CodeIgniter以联系表格成功发送电子邮件? [英] How to successfully send an email in a contact form through CodeIgniter?
问题描述
我已设置好我的控制器和我的联系表单。但是当我在我的联系页面上单击提交时,我没有收到错误,但我没有收到电子邮件。任何人可以帮助我弄清楚为什么我没有收到电子邮件?我欣赏任何帮助。这里是我的控制器代码:
I have set up my controller and my contact form all set up. But when I click "Submit" on my contact page, I receive no errors but I receive no email. Can anyone help me figure out why I am not actually receiving the email? I appreciate any help. Here is my code for the controller:
<?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('anish@develop.io');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');
$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');
}
}
这里是我的联系页面视图的代码:
And here is my code for my contact page view:
<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>
推荐答案
启用 php_openssl.dll
在 php.ini
文件并尝试使用gmail。 Pascal Spruit或Omade的答案会奏效。不要忘记在 php.ini
文件中编辑后重新启动本地服务器。
enable php_openssl.dll
in php.ini
file and try using gmail. The answer of Pascal Spruit or Omade will work. Don't forget to restart you local server after editing in php.ini
file.
这篇关于如何通过CodeIgniter以联系表格成功发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!