2013-02-28 47 views
0

我使用CodeIgniter發送郵件。數據發送給控制器,但問題在於編碼。郵件功能在CodeIgniter中不起作用

腳本用於:

$(".alert_button").click(function(){  
    var emailmy= $("#emailmy").val(); 
    $.ajax({ 
      url: "<?php echo site_url('home/ForgotEmailValidation'); ?>", 
      data: { 
       emailmy: emailmy 

      }, 
     // context: document.body, 
      success: function(ret) 
      { 
       if(ret=="0") 
       { 
        $(".login_alert").show(); 
        $(".login_ok").hide(); 
        $('#emailmy').focus(); 
        return false; 
       } 
       else 
       { 

         $.post("<?php echo site_url('home/ForgotPasswordMail');?>",{emailmy:emailmy},function(data){ 

        }); 

        $(".login_ok").show(); 
        $(".login_alert").hide(); 

        return true; 
       } 

      } 
    }); 

});

控制器:

//$randomString is used for send random string. 

$characters = 'abcdefghijklmnopqrstuvwxyz'; 
    $randomString = ''; 
    for ($i = 0; $i < 20; $i++) { 
     $randomString .= $characters[rand(0, strlen($characters) - 1)]; 
    } 

    $to = $emailMY; 
    $subject = "Reset your password on Pictraveler"; 
    $message = "Thank you for using Pictraveler.com.<br/>Please go to this page to create your new password.<br/>The link will expire in 24 hours.<br/>[Reset Password]<br/><a herf='http://133.242.3.198/resetpassword/$randomString'>http://www.pictraveler.com/resetpassword?$randomString</a>"; 
    $from = "[email protected]"; 
    $headers = "From:" . $from; 
    mail($to,$subject,$message,$headers); 
+0

是否在本地.. ??如果是的話,使用SMTP ... swiftmailer會幫助很多。 – 2013-02-28 09:08:33

+0

沒有。在服務器上運行 – 2013-02-28 09:09:37

+0

檢查當你嘗試發送郵件時是否所有的參數都得到了。或者發佈了什麼錯誤。 – 2013-02-28 09:09:55

回答

0

更好地利用谷歌SMTP

建立在你的config文件夾 'email.php'

$config['protocol'] = 'smtp'; 
$config['smtp_host'] = 'ssl://smtp.googlemail.com'; 
$config['smtp_port'] = '465'; 
$config['smtp_timeout'] = '30'; 
$config['smtp_user'] = '[email protected]'; 
$config['smtp_pass'] = 'yourpassword'; 
$config['charset'] = 'utf-8'; 
$config['newline'] = "\r\n"; 

一個配置文件,並在您的控制器以這種方式發送電子郵件

$this->email->clear(TRUE); 
$this->email->set_mailtype("html"); 
$this->email->from($mailFrom, $mailFromName); 
$this->email->to($toEmail); 
$this->email->subject($emailSubject); 
$this->email->message($emailContent); 
$this->email->send(); 
0

嘗試用

$headers = "-f:" . $from;
代替
$headers = "From:" . $from;

+0

我認爲附近郵件發生錯誤($ to,$ subject,$ message,$ headers); – 2013-02-28 09:24:51

+0

這個答案是錯誤的 - 請閱讀mail()的文檔和預期的標題格式。 – andr 2013-02-28 09:46:34