简体   繁体   中英

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.

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:

<?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/"! If i put double 'h': "hhttps://www.example.net/" in the email will be the right one: " 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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