我用phpmailer類做發送郵件功能,提示500錯誤Internal Server Error;
調用代碼都應該沒問題,接網上執行個體寫的,
是不是在做這個功能之前,還需要什麼別的步驟或配置才可以發送郵件呢?
回複討論(解決方案)
出現 500 錯誤就表示你的代碼有問題!
開啟 php 的錯誤顯示功能,調試一下
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log
一運行就直接提示這個了,也沒報什麼錯。
require("./class.phpmailer.php");$mail = new PHPMailer();$mail->IsSMTP();// 啟用SMTP$mail->Host = "smtp.sina.cn";//SMTP伺服器$mail->SMTPAuth = true;//開啟SMTP認證$mail->Username = "fgrhda";// SMTP使用者名稱$mail->Password = "123456";// SMTP密碼$mail->From = "fgrhda@163.com";//寄件者地址$mail->FromName = "Mailer";//寄件者$mail->AddAddress("97235694@qq.com", "Josh Adams");//添加收件者//$mail->AddAddress("ellen@example.com");$mail->AddReplyTo("97235694@qq.com", "Information");//回複地址$mail->WordWrap = 50;//設定每行字元長度/** 附件設定$mail->AddAttachment("/var/tmp/file.tar.gz");// 添加附件$mail->AddAttachment("/tmp/image.jpg", "new.jpg");// 添加附件,並指定名稱*/$mail->IsHTML(true);// 是否HTML格式郵件$mail->Subject = "Here is the subject";//郵件主題$mail->Body = "This is the HTML message body in bold!";//郵件內容$mail->AltBody = "This is the body in plain text for non-HTML mail clients";//郵件內文不支援HTML的備用顯示if(!$mail->Send()){ echo "Message could not be sent. "; echo "Mailer Error: " . $mail->ErrorInfo; exit;}echo "Message has been sent";
這代碼是這樣的,按執行個體來的
提示兩行代碼,沒讀懂是什麼意思
在php檔案頁頭加上
date_default_timezone_set("PRC"); 試試看。
或者php.ini 中設定時區: date.timezone=PRC