2016-09-18 118 views
1

我遇到了一個使用PHPmailer的問題,我只是不明白。對於在所示位置100%工作的標題功能,我有一個輔助功能重定向。它不能在我希望它工作的評論中顯示的位置上工作。無論放置重定向功能的位置如何,其他所有功能都能正常工作。有任何想法嗎?這也是我的第一篇文章,如果已經有我找不到的解決方案,請提前致歉。PHP郵件程序重定向問題

<?php 

if(isset($_POST['replyall'])) { 

    redirect("index.php?leadreply"); // Why does this have to be here to work???? //  

    if(isset($_POST['chk1'])) { 

     $email = new PHPMailer(); 
     $email->From  = $_POST['author']; 
     $email->FromName = 'JGM Decorating'; 
     $email->Subject = 'Reply to your contact request'; 
     $email->Body  = $_POST['comments']; 
     $email->AddAddress($_POST['destination']); 

     $file_to_attach = '../crm/gtcjgm.pdf'; 

     $email->AddAttachment($file_to_attach , 'Terms and Conditions.pdf'); 

     return $email->Send(); 

     // I would like to have the redirect here but it doesn't work??// 

    } else { 

     $email = new PHPMailer(); 
     $email->From  = $_POST['author']; 
     $email->FromName = 'JGM Decorating'; 
     $email->Subject = 'Reply to your contact request'; 
     $email->Body  = $_POST['comments']; 
     $email->AddAddress($_POST['destination']); 

     $file_to_attach = ''; 

     $email->AddAttachment($file_to_attach , 'Terms and Conditions.pdf');  

     return $email->Send(); 

     // I would like to have a different redirect here but it doesn't work??//  

    } 
} 
?> 
+3

因爲你在調用'redirect'之前'返回'。 – tkausl

+0

如果這是真正的代碼,你怎麼認爲你___returning to___它不是一個函數,以便返回時沒有SENCE – RiggsFolly

+0

這從有關郵件附件另一個答案是採取工作代碼。我接受了你的建議並刪除了「返回」。完全按照我想要的那樣工作@RiggsFolly! – Greg

回答

0

此代碼:

return $email->Send(); 

說明:這將返回功能,它會在這個階段本身停止進程,無論行後你把它不會工作。 (E.g)Echo語句也不起作用。

如果你想兩者都做你要做的使用Ajax的郵件發送過程,之後獨自你必須按照你需要重定向。

由於返回將停止在那一瞬間本身的執行。所以爲了做到這一點,您可以將它與AJAX一起使用,然後重定向它。

+0

謝謝!我對這一切都很陌生,但會在AJAX上有所作爲。 – Greg

+0

你必須在AJAX函數的幫助下發送電子郵件,之後你需要根據你所做的請求重定向。 –