简体   繁体   English

Codeigniter:无法发送电子邮件

[英]Codeigniter: unable to send email

I have a "Contact Us" page, where if users submit the form. 我有一个“联系我们”页面,如果用户提交表单,请在该页面上。 Then email should go to the specified email. 然后,电子邮件应转到指定的电子邮件。

After submiting the form i am getting the Success message ,but i am not seeing any email in my inbox/spam. 提交表格后,我收到成功消息,但收件箱/垃圾邮件中没有看到任何电子邮件。

I am testing on my live server . 我正在实时服务器上进行测试。

Pelase help me to solve my problem. 请帮助我解决我的问题。

My code: 我的代码:

<?php
        if ( ! defined('BASEPATH')) exit('No direct script access allowed');

        class contact extends CI_Controller  {
            public function __construct()
            {
                parent:: __construct(); 
                $this->load->helper('url');
                $this->load->helper('form');
                $this->load->library('session');
                $this->load->library('email');
                $this->load->model('shopmodel');
                $this->load->model('contactusmodel');
                $this->load->library('form_validation'); 
            } 

            function index()
            {
                 $this->form_validation->set_error_delimiters(' <li  class="errorlist">', '</li>')->set_rules('fullname', 'Name','trim|required|min_length[5]|max_length[50]|xss_clean');
                 $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('countryname', 'Country','trim|required|min_length[2]|max_length[50]|xss_clean');
                 $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('email', 'Email', 'trim|required|valid_email');
                 $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('contactdetails', 'Contact Details','trim|required|min_length[40]|max_length[2000]|xss_clean');
                 $data=$this->contactusmodel->contactusmodel();
                 $data["query"] = $this->shopmodel->getshopdetailsById(199);//taking data as shop id 199 

                  if($this->form_validation->run() === FALSE)
                  {  
                        $data['ffullname']['value'] = $this->input->post('fullname');
                        $data['fcountryname']['value'] =$this->input->post('email');
                        $data['femail']['value'] = $this->input->post('countryname'); 
                        $data['fcontactdetails']['value'] =$this->input->post('contactdetails'); 
                        $this->load->view('contact/contact',$data);  
                  }

                  else if ($this->form_validation->run() === TRUE)
                  {
                      $name=$this->input->post('fullname');
                      $sendersemail=$this->input->post('email');
                      $fromcountry=$this->input->post('countryname');
                      $message=$this->input->post('contactdetails'); 

                      $config = Array(
                        'protocol' => 'smtp',
                                'smtp_host' => 'ssl://smtp.googlemail.com',
                                'smtp_port' => 465,
                                'smtp_user' => 'ashutosh10g@gmail.com',
                                'smtp_pass' => 'xxxxxxxx',
                                'mailtype'  => 'html', 
                                'charset' => 'utf-8',
                                'wordwrap' => TRUE

                     );

                       $this->load->library('email', $config);
                       $this->email->set_mailtype("html");
                        $this->email->set_newline("\r\n");
                        $email_body ="<div>hello world</div>";
                        $this->email->from('ashutosh10g@gmail.com', 'ddd');

                        $list = array('ashutosh10g@gmail.com');
                        $this->email->to($list);
                        $this->email->subject('Testing Email');
                        $this->email->message($email_body);

                        $this->email->send();
                        echo $this->email->print_debugger(); 
                  }
                  else{
                      $this->load->view('contact/contact',$data);  
                  }
            }
        }
        ?>

What output i am getting is: 我得到的输出是:

    [code]
    Your message has been successfully sent using the following protocol: mail
    From: "ddd" 
    Return-Path: 
    Reply-To: "ashutosh10g@gmail.com" 
    X-Sender: ashutosh10g@gmail.com
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <513e1456185d4@gmail.com>
    Mime-Version: 1.0
    Content-Type: multipart/alternative; boundary="B_ALT_513e1456185e3"


    =?utf-8?Q?Testing_Email?=
    This is a multi-part message in MIME format.
    Your email application may not support this format.

    --B_ALT_513e1456185e3
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: 8bit

    hello world


    --B_ALT_513e1456185e3
    Content-Type: text/html; charset=utf-8
    Content-Transfer-Encoding: quoted-printable

    <div>hello world</div>

    --B_ALT_513e1456185e3--

Maybe you are experimenting a relaying error somtimes the Google Server don't accept relay mail form one MTA to another inbox. 也许您正在尝试中继错误,因此Google Server有时不接受从一个MTA到另一个收件箱的中继邮件。 Try to test to establish an SMTP dialog to your server an try to send the mail. 尝试测试以建立到服务器的SMTP对话框,然后尝试发送邮件。 Here is a simple SMTP dialog example: 这是一个简单的SMTP对话框示例:

http://www.soi.wide.ad.jp/class/20000009/slides/11/6.html http://www.soi.wide.ad.jp/class/20000009/slides/11/6.html

Try to send a mail if the server sends a relay error you should try with another SMTP server. 如果服务器发送中继错误,请尝试发送邮件,您应该尝试使用另一台SMTP服务器。 If not maybe is a missconfiguration of your php. 如果不是,也许是您的php的配置错误。

But in my experience gmail always deny the relaying mail for spam and security reasons if the MTA is not a trusted agent. 但是根据我的经验,如果MTA不是受信任的代理,gmail总是出于垃圾邮件和安全原因而拒绝中继邮件。

Another reason may be that you don't have correctly configure DNS Servers and your MTA cannot find the MX Records. 另一个原因可能是您没有正确配置DNS服务器,并且您的MTA无法找到MX记录。 Example y your MTA is sendmail it notifies php tha the mail was send succesfully but if you look into sendmail logs you can find that the host is unreachable. 例如,您的MTA是sendmail,它通知php邮件已成功发送,但是如果查看sendmail日志,您会发现主机无法访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM