我正在建立一个网站,当用户进行注册时,我需要在该网站上发送电子邮件。
电子邮件发送没有问题,但是在我的“ 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/”。
出什么问题了?
P.s。该链接甚至不适用于图像,并且所有链接均通过电子邮件发送。
答案 0 :(得分:1)
尝试使用双引号并转义那些属于邮件文本的人:
$message = "<a href=\"https://www.example.net/path/?Verify=". $IDVer ."\"> here</a>";