我正在处理电子邮件功能,因为我已经设置了SMTP,电子邮件正在为gmail工作,但是对于电子邮件提供商,邮件将进入垃圾邮件文件夹,请问有人可以帮助我解决该问题吗?这是我的代码
$config['protocol'] = 'smtp';
$config['smtp_host'] = SMTP_HOST;
$config['smtp_user'] = SMTP_USER;
$config['smtp_pass'] = SMTP_PASSWORD;
$config['smtp_port'] = '587';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->load->library('email', $config);
$this->email->set_header('Content-Type', 'text/html');
$this->email->from(FROM_EMAIL);
$this->email->to($email);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
$this->email->subject("Test email");
$this->email->message("Testing Mail received.");
if($this->email->send()){
echo "Email send.";
} else {
echo "Error";
}
答案 0 :(得分:0)
嗨,请尝试这样设置SMTP。 这段代码对我有用。
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMPTAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 587;
$mail->Username = "my@email.com";
$mail->Password = "password";
答案 1 :(得分:0)
嗨,请尝试一下。
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'SMTP_USER';
$config['smtp_port'] = '587';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'SMTP_USER';
$config['smtp_pass'] = 'SMTP_PASSWORD';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('SMTP_USER', 'Name');
$this->email->to($emailTo);
$this->email->subject('subject here');
$this->email->message('message here');
$this->email->send();
答案 2 :(得分:0)
尝试此配置
$config = array(
'protocol' => 'SMTP',
'mailtype' => 'html',
'smtp_host' => '*********',
'smtp_port' => '********',
'charset' => 'UTF-8',
'newline' => "\r\n",
'auth' => true,
'mailpath' => '/usr/sbin/sendmail',
'validate' => 'FALSE',
);
$this->email->clear();
$this->email->set_newline("\r\n");
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_crlf( "\r\n" );
$this->email->from("*****", "*****");
$this->email->to($row->email);
$this->email->subject("******");
$this->email->message($mesg);