3 回答

TA貢獻1833條經驗 獲得超4個贊
PHPMailer 默認情況下不會拋出異常 - 您必須通過傳遞給構造函數來請求異常true
,如$mail = new PHPMailer(true);
.?如果沒有它,您必須檢查方法的返回值,例如send()
確定它們是否有效。
錯誤存儲在ErrorInfo
屬性中。
您還可以設置$mail->SMTPDebug = 2;
查看郵件服務器的內容。

TA貢獻1765條經驗 獲得超5個贊
我的最終工作代碼是:
function Redirect_to($New_Location){
header("Location:" . $New_Location);
exit;
}
if(isset($_POST['Submitenq'])){
require('phpmailer/PHPMailerAutoload.php');
define ('GUSER','[email protected]');
define ('GPWD','mailpass');
$recever1 = '[email protected]';
$enq_name = $_POST["enq_name"];
$enq_email = $_POST["enq_email"];
$enq_phone = $_POST["enq_phone"];
$enq_message = $_POST["enq_message"];
date_default_timezone_set("Asia/Kolkata");
$CurrentTime = time();
$DateTime = strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($enq_name) || empty($enq_email) || empty($enq_phone) || empty($enq_message)){
Redirect_to("index.php?error=1");
}else{
$mail = new PHPMailer(true);
try{
$mail->IsSMTP();
$mail->Mailer = "smtp";
// $mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "none";
$mail->Port = 25;
$mail->Host = "mail.supremecluster.com";
// $mail->CharSet = "UTF-8";
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->isHTML(true);
$mail->setFrom($enq_email,$enq_name);
$mail->From = GUSER;
$mail->FromName = $enq_name;
$mail->addAddress($recever1);
$mail->Subject = 'Enquiry Mail from - '. $enq_name;
$mail->Body = '<table class="table" cellspacing="0">
<thead>
<tr>
<th colspan="2">Enquiry Mail from - '. $enq_name .'</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">'. '<p>Dear Sir / Madam, I have some enquiries. My Details are as follows :</p></br>' .'</td>
</tr>
<tr>
<td>Email:</td>
<td>'. $enq_email .'</td>
</tr>
<tr>
<td>Phone No:</td>
<td>'. $enq_phone .'</td>
</tr>
<tr>
<td>Message:</td>
<td>'. $enq_message .'</td>
</tr>
<tr>
<td>Date and TIME of Enquery:</td>
<td>'. $DateTime .'</td>
</tr>
</tbody>
</table>';
$mail->send();
$success_msg = "Your Message Sent Successfully: ";
}catch(phpmailerException $e){
echo $e->errorMessage();
}catch(Exception $e){
echo $e->getMessage();
}
我決定從我自己的服務器而不是 Gmail 服務器發送郵件:
所以我改變了:
$mail->SMTPSecure = "ssl";
到
$mail->SMTPSecure = "none";
最重要的是要記?。?/p>
$mail->Username = GUSER;
和
$mail->From = GUSER;
必須相同
和
另外,我們必須將 true 傳遞給構造函數:
$mail = new PHPMailer(true)
// 構造函數中的參數 true 啟用異常
- 3 回答
- 0 關注
- 146 瀏覽
添加回答
舉報