我正在通过phpmailer发送gmail邮件,其中包含一个链接,该链接将重定向到我在localhostxampp的php页面上

问题描述

我正在通过PHPmailer发送gmail邮件,其中包含一个链接,该链接重定向到我在localhost(xampp)的PHP页面上。但是它无法在我的本地主机的PHP页面重定向这是链接我的本地主机页面代码

  $mail->isHTML(true);                         // Set email format to HTML
  $mail->Subject = 'MilkBank Account Verification';
  $mail->Body    = 'Click the link to verify your account.<br>  
 <a href="http:localhost//MilkBank2.0/UserPages/BackEnd/verify.be.update" >Register Account!! </a>';

  $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

  $mail->send();

是否可以重定向它?

解决方法

只需添加if-else标签

if ($mail->Send()) 
{ 
    header("Location:Yourfile.php");//echo "Message Sent!";            
}

else
{
   echo "Message could not be sent.  ";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit; 
}