我正在使用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);
答案 0 :(得分: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();
答案 1 :(得分:0)
尝试用
$headers = "From:" . $from;
替换
$headers = "-f:" . $from;