0

我正在使用 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 = "someonelse@example.com";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
4

2 回答 2

0

更好地使用 Google SMTP

在您的配置文件夹“email.php”中创建一个配置文件

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '30';
$config['smtp_user'] = 'youremail@gmail.com';
$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();
于 2013-02-28T09:15:31.667 回答
0

尝试更换

$headers =“发件人:”。$来自;
$headers = "-f:" 。$来自;

于 2013-02-28T09:19:00.343 回答