dongzong3053 2014-07-01 15:14
浏览 11
已采纳

PHP邮件查询[关闭]

So I am using and successfully sending emails out using PHPmailer yet once the email sends I am not sure where to put the page redirect back to the page you came from with a message saying message sent perhaps?

<?php

if (isset($_POST['hp']) && $_POST['hp'] && $_POST['hp'] != '') {    

}

else {

require 'c:\php\includes\PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = '';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '';                            // SMTP username
$mail->Password = '';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail->Port =;

$mail->From = '';
$mail->FromName = '';


foreach ($members as $user) {

$mail->addAddress($user->user_email);  

}

foreach ($committee as $user) {

$mail->AddCC($user->user_email);  

}





$mail->WordWrap = 50;                                 // Set word wrap to 50 characters

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $_POST["Subject"];
$mail->Body    = $_POST["contentfield"];





if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;

}
}

?>

I have taken all my details out for obvious reasons.

  • 写回答

3条回答 默认 最新

  • dongwu5801 2014-07-01 15:19
    关注

    Why not add an else to your if() mail doesn't send statement and redirect the user if the if statement does not fail?

    if(!$mail->send()) {
       echo 'Message could not be sent.';
       echo 'Mailer Error: ' . $mail->ErrorInfo;
       exit;
    
    } else {
      // email sent successfully, redirect to success page
      header ('Location: sent.php');
    }
    

    Your email should still send because the browser will only redirect you if $mail->send() evaluates to true... and at this point the mail has already sent.

    You could also put the redirect after the if() statement if you wanted to and that should also work because if your if() statement evaluates to true it will exit the script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line