我想发送一封电子邮件,但是当我发送它时,会出现这样的问题: 致命错误:未捕获错误:在C:\ xampp \ htdocs \ rapor \ admin \ mail.php中调用未定义函数setContext():27堆栈跟踪:#0 {main}在C:\ xampp \ htdocs \中抛出第27行的rapor \ admin \ mail.php
我从URL获取“id”,在 mail.php 页面中使用SELECT获取查询。
这是我的代码:
<?php
require '../PHPMailer/PHPMailerAutoload.php';
require '../config/connect.php';
$kodenilai = $_GET["id"];
$queryKirim = mysqli_query($konek,"SELECT nilai.*, pelajaran.nama_pelajaran, siswa.nama_siswa, siswa.nis FROM siswa, pelajaran, nilai, datakelas, kelas
WHERE nilai.kode_siswa=siswa.kode_siswa
AND nilai.kode_pelajaran=pelajaran.kode_pelajaran
AND datakelas.kode_siswa=siswa.kode_siswa
AND datakelas.kode_kelas=kelas.kode_kelas
AND kelas.kode_kelas=nilai.kode_kelas
AND nilai.kode_nilai='$kodenilai'")or die("gagal".mysqli_error());
$data=mysqli_fetch_array($queryKirim);
$dataNilai['nis'] = $data['nis'];
$dataNilai['nama_siswa'] = $data['nama_siswa'];
$dataNilai['semester'] = $data['semester'];
$dataNilai['nama_pelajaran']= $data['nama_pelajaran'];
$dataNilai['nilai_tugas'] = $data['nilai_tugas'];
$dataNilai['nilai_tugas2'] = $data['nilai_tugas2'];
$dataNilai['nilai_tugas3'] = $data['nilai_tugas3'];
$dataNilai['nilai_uts'] = $data['nilai_uts'];
$dataNilai['nilai_uas'] = $data['nilai_uas'];
function setContext($data) {
$postdata = http_build_query($data);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
return stream_context_create($opts);
}
$context = setContext($dataNilai);
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "mail.besp.gq";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "********";
$mail->Password = "********";
$mail->setFrom('info@besp.gq', 'Info');
$mail->addReplyTo('admin123@besp.gq', 'Admin');
$mail->addAddress('ujangujing765@gmail.com', 'ujangujing765');
$mail->Subject = 'PHPMailer SMTP test';
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->msgHTML(file_get_contents('mail-temp/content.php', false, $context));
$mail->AltBody = 'This is a plain-text message body';
//$mail->addAttachment('images/phpmailer_mini.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
在上面的脚本中,我设置了setContext是数据数组。有问题吗?
先谢谢..