简体   繁体   English

PHP:使用邮件发送链接无法正常工作

[英]PHP: sending link with mail don't work correctly

i'm building a website where i need to send an e-mail when a user make a registeration. 我正在建立一个网站,当用户进行注册时,我需要在该网站上发送电子邮件。

The e-mail is sent without problems but on my "href='link' or src='link'", the link breaks in the mail. 电子邮件发送没有问题,但是在我的“ href ='link'或src ='link'”上,链接在邮件中断开了。

Here is the code: 这是代码:

<?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'];
    }
?>

Here is the SendEmail() function: 这是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);
}
?>

The URL: " https://www.example.net/ " in the email is: "ttps://www.example.net/"! 电子邮件中的URL:“ https://www.example.net/ ”是:“ ttps://www.example.net/”! If i put double 'h': "hhttps://www.example.net/" in the email will be the right one: " https://www.example.net/ ". 如果我在电子邮件中加上双“ h”:“ hhttps://www.example.net/”将是正确的一个:“ https://www.example.net/ ”。

What's the problem? 有什么问题?

Ps the Link doesn't even work with image and all links sended in the e-mail. Ps链接甚至无法处理图像,并且所有链接都通过电子邮件发送。

尝试使用双引号并转义那些属于邮件文本的人:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM