2014-02-09 83 views
0

我已经遵循一个教程来发送邮件从PHP。邮件不发送在php

public function send_credentials($beneficiary_user){ 

    $this->load->library(‘email’); 
    $email_config = Array(
     'protocol' => 'smtp', 
     'smtp_host' => 'ssl://smtp.googlemail.com', 
     'smtp_port' => '465', 
     'smtp_user' => '[email protected]', 
     'smtp_pass' => 'apptesting', 
     'mailtype' => 'html', 
     'starttls' => true, 
     'newline' => "\r\n" 
    ); 
    $this->email->from('[email protected]', 'invoice'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('Invoice'); 
    $this->email->message('Test'); 

    $this->email->send(); 

} 

什么其他的设置,我必须做,使之工作 *回声运行后$这个 - >的电子邮件 - > print_debugger();.我得到了*

无法使用PHP邮件()发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。

User-Agent: CodeIgniter 
    Date: Sun, 9 Feb 2014 14:58:44 +0530 
    From: "invoice" 
    Return-Path: 
    Reply-To: "[email protected]" 
    X-Sender: [email protected] 
    X-Mailer: CodeIgniter 
    X-Priority: 3 (Normal) 
    Message-ID: <[email protected]> 
    Mime-Version: 1.0 
    Content-Type: multipart/alternative; boundary="B_ALT_52f74a4c41e88" 
     =?utf-8?Q?Invoice?= 
     This is a multi-part message in MIME format. 
     Your email application may not support this format. 
    --B_ALT_52f74a4c41e88 
    Content-Type: text/plain; charset=utf-8 
    Content-Transfer-Encoding: 8bit 
    Test 
    --B_ALT_52f74a4c41e88 
    Content-Type: text/html; charset=utf-8 
    Content-Transfer-Encoding: quoted-printable 
    Test 
    --B_ALT_52f74a4c41e88--

+1

你可以描述你所得到的错误,无论是在控制台还是在你的错误日志中 –

+3

你对'$ email_config'数组没有做任何事情。当你实例化它时,你应该将它传递给电子邮件库。 – Mark

+0

调用'$ this-> email-> initialize($ config);'初始化你设置的配置变量,或者在构造函数中传递它''this-> load-> library('email',$ config);' –

回答

3

既然我们在评论中找到了问题的答案,写出答案似乎是谨慎的。

问题是你的电子邮件配置数组没有做任何事情($email_config)。虽然您可能会或可能没有在此处定义正确的设置,但由于没有正确使用,所以它们没有任何意义。

因此,在最起码,你必须改变你的代码以反映以下更改:

$email_config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => '465', 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'apptesting', 
    'mailtype' => 'html', 
    'starttls' => true, 
    'newline' => "\r\n" 
); 

$this->load->library('email', $email_config); 

请注意,这将仅仅是解决这个问题跟你的方法,我无法核实你的设置信誉/访问凭证。

编辑:

按jtheman的建议,我决定挖一个深一点。你可能想看看这个https://stackoverflow.com/a/17274496/2788532

编辑#2:

您可以从CI的电子邮件类使用下面的代码(后您尝试发送邮件,当然)访问有用的错误信息:

<?php echo $this->email->print_debugger(); ?> 
+0

正确!其他方法可能是:1.尝试smtp.gmail.com,2.端口587,3.检查你的防火墙等 – jtheman

+0

我试过这个了。但我不知道我在哪里犯错 – user3289150

+1

@ user3289150看到我的第二次编辑调试你的代码。 – Mark

0

只需添加这在功能的开始,你正在编写发送电子邮件代码

$config = Array(
      'protocol' => 'sendmail', 
      'mailtype' => 'html', 
      'charset' => 'utf-8', 
      'wordwrap' => TRUE 

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

电子邮件会转发但错误相同的错误将显示

0

,你可以尝试这个

  1. 开放系统/库/ email.php

  2. 编辑

    变量$换行符= “\ n”; var $ crlf =“\ n”;

    变量$换行符= “\ r \ n” 个; var $ crlf =“\ r \ n”;