Link within variable string php

0

I intend to send an email in php and for that I prepare the variable $cuerpo that I need to contain a link. As seen below, I tried to do echo '<a href="https://datoweb.com">Enlace</a>' But it has not worked.

 $cuerpo= "Para confirmar su registro, por favor pulse  en este". echo '<a href="https://datoweb.com">Enlace</a>';
        $para=$email;
        $de='[Registro Web]'.' Dni: ['.$_POST["dni"]. '] Nombre:  '. $_POST["nombre"] ;
        $headers = 'From: ' . "\r\n" .
         'Reply-To: ' . "\r\n" .
         'X-Mailer: PHP/' . phpversion();
        mail($para,$de,$cuerpo,$headers); 

Using the link of campaigner Vera Canet I have tried to send the email as a web and this way it has turned out to me, it is much more beautiful aesthetically.

$cuerpo = "Formulario de registro \n";
$cuerpo = '<html>'.
   '<head><title>Registro </title></head>'.
   '<body><h1>Bienvenid@ '.$nombre.'</h1>'.
   'Haga click en este  <a href="www.google.es"><b>Enlace</b></a> para 
    activar su cuenta de usuario en el privada'.
    '<hr>'.
    'Enviado por Grupo la Caña'.


 '</body>'.
    '</html>';

            $para=$email;
            $de='[Registro Web]'.' Dni: ['.$_POST["dni"]. '] Nombre:  '. 
           $_POST["nombre"] ;
            $headers ='Reply-To:[email protected] ' . "\r\n" .        
            $headers = 'From: [email protected]' . "\r\n" .
            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
             mail($para,$de,$cuerpo,$headers); 
    
asked by Lorenzo Martín 19.06.2018 в 17:41
source

1 answer

0

Within a value assignment to a variable you can not use a echo , just concatenate it. On the other hand, if what you need is that the link is that, a link, in the email that the user receives, you must put the appropriate headers, including the mime and the content type.

In my comments you have the link where they explain those two headers, which I also expose here below modifying your code and adding the two headers

$cuerpo= "Para confirmar su registro, por favor pulse  en este <a href='https://datoweb.com'>Enlace</a>";
$para=$email;
$de='[Registro Web]'.' Dni: ['.$_POST["dni"]. '] Nombre:  '. $_POST["nombre"] ;
$headers = 'MIME-Version: 1.0' . "\r\n".
           'Content-type: text/html; charset=utf-8' . "\r\n".
           'From: ' . "\r\n" .
           'Reply-To: ' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();
mail($para,$de,$cuerpo,$headers); 
    
answered by 19.06.2018 в 17:45