我有一个网站,当网络有一定的条件时,如果($ status =="接受")那么网页将在这个问题的下方加载代码,所以代码将加载在页面上,当我想要发送电子邮件的条件时,我尝试编写类似于下面的代码,但它不起作用。
<?php
if($keterangan != 'id_card' && $userId == $userData['id']){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587,
'smtp_user' => 'example@gmail.com',
'smtp_pass' => 'example'
);
$nama = $userData['nama_lengkap'];
$email = $userData['email'];
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('example@gmail.com', 'blabla');
$this->email->to($email);
$this->email->subject('bla bla bla');
$this->email->message('hello');
if($this->email->send()){;
redirect('dashboard','refresh');
}else{
$this->session->set_userdata('id_tmp',$id2);
redirect('view_pengumuman','refresh');
}
}
?>
&#13;
编辑
require_once('./asset/phpmailer/class.phpmailer.php');
require_once('./asset/phpmailer/class.smtp.php');
$mail = new PHPMailer();
$message = "hello";
$subject = "hello";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "ssl://smtp.googlemail.com"; // sets the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "xxxxxxxo@gmail.com";
$mail->Password = "xxxxxxxxxxx";
$mail->SetFrom( 'xxxxxxxx@gmail.com', 'COMPANY' );
$mail->AddAddress( 'xxxxxxx@gmail.com', 'some people' );
$mail->Subject = $subject;
$mail->MsgHTML($message);
$sendEmail = $mail->Send();
if( $sendEmail == true )
{
redirect('view_pengumuman','refresh');
}
else
{
redirect('dashboard','refresh');
}
}
?>
&#13;