首页 > 解决方案 > 我正在通过 phpmailer 在 gmail 中发送消息,其中包含一个链接,该链接将在 localhost(xampp)中的我的 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();

可以重定向吗?

标签: phpxampplocalhostphpmailer

解决方案


只需添加 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; 
}

推荐阅读