PHP邮件重定向问题

时间:2016-09-18 14:00:52

标签: php phpmailer

我遇到了一个使用PHPmailer的问题,我不明白。我有一个辅助功能重定向头功能,在所示位置100%工作。它无法在我希望它工作的评论中显示的位置工作。无论重定向功能放在何处,其他所有功能都能完美运行。有任何想法吗?这也是我的第一篇文章,如果已经有一个我无法找到的解决方案,请提前道歉。

<?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??//      

    }
}
?>

1 个答案:

答案 0 :(得分:0)

此代码:

return $email->Send();

说明:这将返回该函数,它将在此阶段停止进程,然后在您放置的任何行之后它将无效。 (例如)Echo声明也不起作用。

如果你想同时做两件事,你必须使用Ajax进行邮件发送过程,之后你必须根据需要重定向。

由于返回将在该时刻自行停止执行。所以为了做到这一点,你可以使用它与AJAX,然后重定向它。