【问题标题】:Broken link within an email sent with PHP使用 PHP 发送的电子邮件中的链接损坏
【发布时间】:2015-11-18 08:49:30
【问题描述】:

我在尝试使用 php 发送带有电子邮件的链接时遇到了一个奇怪的问题。此链接只会将用户带到“更新密码”表单。但是,当我单击该链接时,它会将我带到浏览器中名为“about:blank”的空白页面。我真的不明白为什么会这样......这是我的代码:链接的 html 在 $msg 变量中。

$to     = $email;

$msg    = "Hello $username, your pin # is $pin. Please remember this pin
                because you will need it on the update password form. <br> 
                Please <a href = \"google.com\">click here</a> to be brought to the update password form.";

$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: ForgottenPassword@PHPGang.com' . "\r\n" .
                'Reply-To: ForgottenPassword@PHPGang.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();    

mail($to,"Forgotten Password",$msg,$header);

我什至尝试将 google.com 作为目的地,但它仍然将我带到那个讨厌的 about:blank 页面。有什么想法吗?

【问题讨论】:

    标签: php email hyperlink html-email


    【解决方案1】:

    您需要在链接中使用完全限定的 URL、协议和所有内容。

    $msg    = "Hello $username, your pin # is $pin. Please remember this pin
                    because you will need it on the update password form. <br> 
                    Please <a href = \"http://google.com\">click here</a> to be brought to the update password form.";
    

    【讨论】:

      【解决方案2】:

      尝试如下更改,这里缺少将http添加到url,

      <a href = \"google.com\">click here</a>
      

      <a href = \"http://google.com\">click here</a>
      

      【讨论】:

      • 为什么 OP 应该“试试这个”?一个好的答案总是会解释所做的事情以及这样做的原因,不仅是为了 OP,而且对于未来的 SO 访问者也是如此。 这不是您第一次被要求更好地限定您的答案。
      猜你喜欢
      • 2016-10-20
      • 2014-11-22
      • 1970-01-01
      • 2011-06-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      相关资源
      最近更新 更多