我运行的脚本用于发送带附件的电子邮件。 在我的旧服务器上,它工作得很好,但自从移动几天后。该脚本不再有效。一旦它发送邮件,它就会爆炸。
我确实在错误日志文件中发现了这个错误,我该如何找到问题?
[08-Jul-2015 12:39:17 UTC] PHP Fatal error: Call to undefined function mime_content_type() in /home/username/public_html/editor/cronjob.php on line 79
我的代码或多或少如下所示:
function sendmailwithattachment($from,$to,$subject,$body,$host,$username,$password,$body_id,$port) {
$query = "SELECT * FROM `email_attachments` where `email_id`='$body_id';";
if($result = mysqli_query($this->link, $query)){
if($result->num_rows!=0){
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($body);
while ($row = mysqli_fetch_array($result,1)) {
$attachment=$row['attachment'];
$mime->addAttachment($attachment, mime_content_type($attachment));
}
$body = $mime->get();
$headers = $mime->headers($headers);
} else {
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject,'Content-type' => 'text/html;charset=iso-8859-1');
$body = $body;
}
}
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail=$smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo "<p>Message not sent:".$mail->getMessage()."</p>";
return $mail->getMessage();
} else {
//echo "<p>Message successfully sent!</p>";
return 'sent';
}
}
答案 0 :(得分:0)
无论如何看起来像mime_content_type() is deprecated,尝试将其替换为文档中提到的Fileinfo functions。它可能会在此过程中解决您的问题(虽然很难说,因为我们不知道您的代码是什么样的。)