2012-02-10 114 views
0

我已經用下面的代碼發送電子郵件碰到一點問題發送電子郵件失敗作爲非對象specifiying錯誤

$username=$p['register_name']; 
    $email=$p['register_email']; 
    $activation=md5(uniqid(rand(),true)); 
    $password=md5($p['register_password']); 

    $member_data=array 
    (
     'name'=> $username, 
     'email'=> $email, 
     'pass'=> $password, 
     'activation' => $activation 
    ); 

    $bSuccess=$this->blog->insert_member($member_data); 
    if($bSuccess) 
    { 
     $msg="Click the following URL to activate your account :<br/> 
       http://myforums.com/activation.php?email=".urlencode($email)."&key=".$activation; 
     $from="[email protected]"; 
     $this->email->from($from, 'Forums Administrator');  
     $this->email->to($email); 
     $this->email->subject("Account activation"); 
     $this->email->message($msg); 
     if(!$this->email->send()) 
     { 
      echo "Unable to send activation email"; 
     } 
     else 
     { 
      echo "An activation link has been sent to your ".$email.".Follow that link to activate your account"; 
     } 
     //echo $this->email->print_debugger(); 
    } 

運行時錯誤是

A PHP Error was encountered Severity: Notice

Message: Undefined property: Login::$email

Filename: forums/login.php

Line Number: 20

Fatal error: Call to a member function from() on a non-object in login.php on line 20

我想我已經定義的電子郵件'從一開始就變量。這就奇怪了/

UPDATE 我裝的電子郵件庫的構造函數,然後一切正常 儘管如此,新的錯誤顯示爲如下,

A PHP Error was encountered Severity: Warning

Message: mail() [function.mail]: SMTP server response: 553 5.5.4 ... Real domain name required for sender address

Filename: libraries/Email.php

Line Number: 1553

回答

2

$this->email看起來像一個幫助你需要先加載。會很高興地看到整個文件/功能

$this->load->library('email');需要定義可以從

使用$這 - >的電子郵件 - >前thenext答案是

[email protected]

不是有效的電子郵件地址。我假設myforum.com不會反向解析DNS,而您使用的服務器是反向解析DNS。

+0

謝謝我更新了我的帖子,請幫我解決新的錯誤 – user1125524 2012-02-10 01:31:31

+0

好吧,所以你是新的。您通常不會在同一問題塊中提出新問題,您將開始一個新問題。這就是說我給了你答案,因爲我確實解決了你的第一個問題,所以請給我答案的答案。 – thenetimp 2012-02-10 01:38:53

0

您是否加載了電子郵件庫?

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

的錯誤是因爲$這個$ email屬性(我假設這是控制器的代碼)未設置,這可能是因爲庫沒有加載。

請參閱docs中的示例。

+0

謝謝,但我仍然有問題我更新我的帖子上面 – user1125524 2012-02-10 01:25:49

+0

我認爲你應該爲這個問題打開另一個問題,但我不知道......無論如何。這似乎是一個服務器問題。查看[this](http://3xsp.blogspot.com/2011/05/real-domain-name-required-for-sender.html)或[this](http://selliott.org/node/40) 。 – 2012-02-10 01:32:45