【问题标题】:PHP: sending link with mail don't work correctlyPHP:使用邮件发送链接无法正常工作
【发布时间】:2018-12-02 17:47:03
【问题描述】:

我正在建立一个网站,当用户注册时我需要发送电子邮件。

电子邮件发送没有问题,但在我的“href='link' 或 src='link'”上,邮件中的链接中断。

代码如下:

<?php
    $to = $UserMail;
    $subject = 'XYZ - Account Verification'; 

    $headers = array("From: XYZ <noreply@XYZ.net>",
                    "Content-type: text/html; charset=ISO-8859-1",
                    "Mime-Version: 1.0",
                    "Content-Transfer-Encoding: quoted-printable",
                    "X-Mailer: PHP/" . PHP_VERSION
    );

    $headers = implode("\r\n", $headers);

    //define the message to be sent. Each line should be separated with \n
    $IDVer = crypt($UserID, '$2a$07$YourSaltIsA22ChrString$');
    $message = "<html>
                    <img src='https://www.example.net/path/image.png' width='1200' height='1200' alt='Logo'>
                    <h1> Hi " . $Username . " welcome to XYZ!</h1><br>
                    Please Verify your account clicking
                    <a href='https://www.example.net/path/?Verify=". $IDVer ."'> here</a>
                </html>";


    $mail_sent = SendEmail($to, $subject, $message, $headers);
    if($mail_sent){
        $success = 'Mail send!';
    }else{
        $Error = 'Mail Error: ' . error_get_last()['message'] . ' on line: '. error_get_last()['line'] . ' on file: '. error_get_last()['file']. ' Error type: ' . error_get_last()['type'];
    }
?>

这里是 SendEmail() 函数:

<?php
ini_set('SMTP','smtp.zoho.com');
ini_set('smtp_port',465);
ini_set('sendmail_from', 'noreply@XYZ.net');



//send the email
function SendEmail($to, $subject, $message, $headers){
    $mail_sent = mail($to, $subject, $message, $headers);
}
?>

电子邮件中的 URL:“https://www.example.net/”是:“ttps://www.example.net/”! 如果我在电子邮件中输入双 'h': "hhttps://www.example.net/" 将是正确的:"https://www.example.net/"。

有什么问题?

附:该链接甚至不适用于图像和电子邮件中发送的所有链接。

【问题讨论】:

  • 你的意思是 zoho 正在吃掉你的h? :p
  • 是的xD,他正在吃“href”或“src”的第一包,我不知道为什么D:

标签: php http email hyperlink phpmailer


【解决方案1】:

尝试使用双引号,将属于邮件文本的部分转义:

$message = "<a href=\"https://www.example.net/path/?Verify=". $IDVer ."\"> here</a>";

【讨论】:

  • 请尝试不使用“Content-Transfer-Encoding:quoted-printable”-header 和/或 UTF-8 字符集。
猜你喜欢
  • 2012-12-13
  • 2013-11-09
  • 2020-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-27
  • 2017-04-30
  • 1970-01-01
相关资源
最近更新 更多