[英]How to successfully send an email in a contact form through CodeIgniter?
我已經設置了我的控制器和我的聯系表單。 但是當我點擊我的聯系頁面上的“提交”時,我沒有收到任何錯誤,但是我沒有收到任何電子郵件。 任何人都可以幫我弄清楚為什么我實際上沒有收到電子郵件? 我感謝任何幫助。 這是我的控制器代碼:
<?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');
}
}
這是我的聯系人頁面視圖的代碼:
<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>
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'yourname@gmail.com',
'smtp_pass' => 'yourpassword',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', $config);
$this->email->from('youremail@gmail.com', 'Jodie');
$this->email->to('toemail@gmail.com');
$this->email->subject('testing email');
$this->email->message('This shows the email worked');
$this->email->send();
echo $this->email->print_debugger();
在php.ini
文件中啟用php_openssl.dll
並嘗試使用gmail。 Pascal Spruit或Omade的答案將起作用。 在php.ini
文件中編輯后,不要忘記重啟本地服務器。
如果它有助於嘗試首先配置電子郵件類
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
嘗試在email-> send()函數周圍添加此代碼,以查看響應是什么
更改$this->email->send();
至
if ( ! $this->email->send())
{
echo 'Some error in sending email';
}
如果錯誤字符串沒有回顯,則問題不在於CI,它可能與郵件服務器有關。
嘗試使用Gmail
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser@gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', config);
$this->email->from('email@gmail.com', 'George');
$this->email->to('email@gmail.com');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
$this->email->send();
echo $this->email->print_debugger();
我也遇到了同樣的問題,但我想知道在gmail上成功發生的一件事情,但只有電子郵件不會發生。
如果我發送$email = $this->input->post('useremail');
那不是gmail。 這是顯示郵件發送成功或你傳遞“如果”條件,但郵件不在郵箱中。 但是,如果我傳遞任何其他東西,如姓名電話密碼或任何東西,這一切都成功。 CI或php是否對電子郵件有任何限制。 因為我在服務器上成功發送html內容,但只有電子郵件不能發送。 還有一件事情,包括電子郵件,但通過本地主機,但我是我的網站上的hostinger並配置一切,一切都很好,但只是電子郵件不傳遞表格,
如果任何人對此有任何想法 - 如何在聯系表格中包含電子郵件,那么請求與我一起剪切您的知識。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.