How to successfully send an email in a contact form through CodeIgniter?

半城伤御伤魂 提交于 2019-12-05 09:06:20

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.

$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();

If it helps try to configure email class first

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

Try to add this code around email->send() function to see what is the response

Change $this->email->send(); To

if ( ! $this->email->send())
{
    echo 'Some error in sending email';
}

If the error string doesn't echo then problem is not with CI, its probably with mail server.

Try using 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();

I also stuck with this same problem but I am figure out one thing every thing going on successfully on gmail but only email not goes.

if I am send $email = $this->input->post('useremail');that is not goes on gmail. It's show mail send successfully or what ever you pass on "if" condition but mail not come in mail box. But if I am pass any thing else like name phone password or any thing, that's all goes successfully. Is there any restriction in CI or php for email. Because I am send html content successfully on server but only email not goes. One more thing every thing send including email but through local-host but I am up my website on hostinger and config everything and everything going great but just email not pass on form,

If any one have any idea about this- how to include email on contact form, then pleas shear your knowledge with me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!