Foros del Web » Programando para Internet » PHP »

Dudas de como integrar html y php

Estas en el tema de Dudas de como integrar html y php en el foro de PHP en Foros del Web. Probablemente sea una duda tonta pero se me dificulta integrar en un formulario etiquetas de html en el correo que se envia, sin mas preambulo ...
  #1 (permalink)  
Antiguo 27/07/2015, 23:17
 
Fecha de Ingreso: julio-2015
Ubicación: San Jose Del Cabo
Mensajes: 2
Antigüedad: 8 años, 9 meses
Puntos: 0
Dudas de como integrar html y php

Probablemente sea una duda tonta pero se me dificulta integrar en un formulario etiquetas de html en el correo que se envia, sin mas preambulo les enseño el intento de codigo para ver si alguien me puede dar una mano, saludos coordiales.

<?php
$suma = 0;

function getValue($field) {
return isset($_POST[$field])?Trim(stripslashes($_POST[$field])):false;
}

$Name = getValue('Name');
$Email = getValue('Email');
$Phone = getValue('Phone');
$Anglers = getValue('Anglers');
$Date = getValue('Date');
$Package = getValue('Package');
$Activity = getValue('Activity');
$Service = getValue('Service');
$Departure = getValue('Departure');
$Beer_drinks = getValue('Beer_drinks');
$Soda_drinks = getValue('Soda_drinks');
$Water_drinks = getValue('Water_drinks');
$Box_lunch = getValue('Box_lunch');
$Bait = getValue('Bait');
$Fishing = getValue('Fishing');

if(getValue('send')) {
if ($Name && $Email && $Date && filter_var($Email, FILTER_VALIDATE_EMAIL)) {
$EmailFrom = "[email protected]";
$EmailTo = "[email protected], $Email";
$Subject = "Desde pagina Cabo.com";
$validationOK=true;

if ($validationOK) {
$Body .= "<!DOCTYPE html>\n";
$Body .= "<html>\n";
$Body .= "<body>\n";
$Body .= "<div id="wrapper" style="margin: 0 auto;padding: 0;position: relative;top: 0;left: 0;width: 800px">\n";
$Body .= "<div id="header" style="position: relative;top: 0;width: 100%;height: 220px;background: url(http://cabomarlini.com/images/cabo-sportfishing-BannerHeader.jpg) no-repeat"/></div>\n";
$Body .= "<div id="container" style="position: relative;width: 100%;height: 580px">\n"
$Body .= "<br/><h1 style="font-size: 28px;text-align: center;margin: 0;padding: 0;color: #265485">CABO MARLINI SPORTFISHING FLEET</h1><br/><p style="color: black;margin: 0;padding: 0">Dear Mr $Name</p>\n";
$Body .= "<p class="bold" style="color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder">YOUR BOOKING IS CONFIRMED WITH CABO MARLINI</p>\n";
$Body .= "<p class="bold" style="color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder">IMPORTANT</p><br/><p style="color: black;margin: 0;padding: 0">Once in Cabo please contact us to confirm your fishing trip and check all details.</p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">Please send to us: </p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">* Anglers number </p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">* Anglers names </p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">* Fishing time </p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">* Booking form </p>\n";
$Body .= "<br/><p style="color: black;margin: 0;padding: 0">We send you a map for our located in Cabo San Lucas and San Jose del Cabo.</p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">If you have any questions we are to serve you: cell phone +52 (624) 122 3253, +52 (624) 141 8114, [email protected]</p>\n";
$Body .= "<p style="color: black;margin: 0;padding: 0">Thanks for your preference. </p><br/><p class="bold" style="color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder">We are waiting for your payment for your reservation. One of our agents will contact you shortly. Thank you for choosing CaboMarlini.</p><br/><p class="bold" style="color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder">In Cabo San Lucas Marina<img src="http://cabomarlini.com/img/pht/CSL.png"/></p>\n";
$Body .= "<p class="bold" style="color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder">In San Jose Del Cabo Puerto Los Cabos<img src="http://cabomarlini.com/img/pht/SJC.png"/></p>\n";
$Body .= "Boat: Tres Marlins 23ft\n";
$Body .= "Name: $Name\n";
$Body .= "Email: $Email\n";
$Body .= "Phone: $Phone\n";
$Body .= "Anglers: $Anglers\n";
$Body .= "Arrival: $Date\n";
$Body .= "Package: $Package\n";
$Body .= "Activity: $Activity\n";
$Body .= "Service: $Service\n";
$Body .= "Departure: $Departure\n";
$Body .= "<p class="bold">In Cabo San Lucas Marina<img src="cabomarlini.com/img/pht/CSL.png"></p>\n";
$Body .= "<p class="bold">In San Jose Del Cabo Puerto Los Cabos<img src="cabomarlini.com/img/pht/SJC.png"></p>\n";
$Body .= "</div>"\n;
$Body .= "</div>"\n;
$Body .= "</body>"\n;
$Body .= "</html>"\n;

$success = @mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
print "<meta http-equiv=\"refresh\" content=\"0;URL=/book_tres_marlins_23ft_payment.php\">";
exit;

} else {
print "<h3 class='error'>Some fields are not filled correctly, please try again.</h3>";
print "<meta http-equiv=\"refresh\" content=\"0;URL=/book_tres_marlins_23ft.php\">";
}

} else {
print "<h3 class='error'>Some fields are not filled correctly, please try again.</h3>";
print "<meta http-equiv=\"refresh\" content=\"0;URL=/book_tres_marlins_23ft.php\">";
}
}
  #2 (permalink)  
Antiguo 28/07/2015, 00:25
 
Fecha de Ingreso: julio-2015
Ubicación: San Jose Del Cabo
Mensajes: 2
Antigüedad: 8 años, 9 meses
Puntos: 0
Respuesta: Dudas de como integrar html y php

if ($validationOK) {
$Body .= "<!DOCTYPE html>\n";
$Body .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
$Body .= "<head>\n";
$Body .= "<meta charset=\"utf-8\">\n";
$Body .= "<title>CaboMarlini Reservation</title>\n";
$Body .= "</head>\n";
$Body .= "<body>\n";
$Body .= "<div id=\"wrapper\" style=\"margin: 0 auto;padding: 0;position: relative;top: 0;left: 0;width: 800px\">\n";
$Body .= "<div id=\"header\" style=\"position: relative;top: 0;width: 100%;height: 220px;background: url(http://cabomarlini.com/images/cabo-sportfishing-BannerHeader.jpg) no-repeat\"/></div>\n";
$Body .= "<div id=\"container\" style=\"position: relative;width: 100%;height: 580px\">\n";
$Body .= "<br/><h1 style=\"font-size: 28px;text-align: center;margin: 0;padding: 0;color: #265485\">CABO MARLINI SPORTFISHING FLEET</h1><br/><p style=\"color: black;margin: 0;padding: 0\">Dear Mr $Name</p>\n";
$Body .= "<p class=\"bold\" style=\"color: black; margin: 0;padding: 0;text-align: center;font-weight: bolder\">YOUR BOOKING IS CONFIRMED WITH CABO MARLINI</p>\n";
$Body .= "<p class=\"bold\" style=\"color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder\">IMPORTANT</p><br/><p style=\"color: black;margin: 0;padding: 0\">Once in Cabo please contact us to confirm your fishing trip and check all details.</p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">Please send to us: </p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">* Anglers number </p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">* Anglers names </p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">* Fishing time </p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">* Booking form </p>\n";
$Body .= "<br/><p style=\"color: black;margin: 0;padding: 0\">We send you a map for our located in Cabo San Lucas and San Jose del Cabo.</p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">If you have any questions we are to serve you: cell phone +52 (624) 122 3253, +52 (624) 141 8114, [email protected]</p>\n";
$Body .= "<p style=\"color: black;margin: 0;padding: 0\">Thanks for your preference. </p><br/><p class=\"bold\" style=\"color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder\">We are waiting for your payment for your reservation. One of our agents will contact you shortly. Thank you for choosing CaboMarlini.</p><br/><p class=\"bold\" style=\"color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder\">In Cabo San Lucas Marina<img src=\"http://cabomarlini.com/img/pht/CSL.png\"/></p>\n";
$Body .= "<p class=\"bold\" style=\"color: black;margin: 0;padding: 0;text-align: center;font-weight: bolder\">In San Jose Del Cabo Puerto Los Cabos<img src=\"http://cabomarlini.com/img/pht/SJC.png\"/></p>\n";
$Body .= "Boat: Tres Marlins 23ft\n";
$Body .= "Name: $Name\n";
$Body .= "Email: $Email\n";
$Body .= "Phone: $Phone\n";
$Body .= "Anglers: $Anglers\n";
$Body .= "Arrival: $Date\n";
$Body .= "Package: $Package\n";
$Body .= "Activity: $Activity\n";
$Body .= "Service: $Service\n";
$Body .= "Departure: $Departure\n";
$Body .= "<p class=\"bold\">In Cabo San Lucas Marina<img src=\"http://cabomarlini.com/img/pht/CSL.png\"></p>\n";
$Body .= "<p class=\"bold\">In San Jose Del Cabo Puerto Los Cabos<img src=\"http://cabomarlini.com/img/pht/SJC.png\"></p>\n";
$Body .= "</div>\n";
$Body .= "</div>\n";
$Body .= "</body>\n";
$Body .= "</html>\n";

Me hacian falta \ para las ", ya quedo eso, ahora una duda por que en los correos que llegan solo codigo y no dezplega el html como es
  #3 (permalink)  
Antiguo 28/07/2015, 01:17
Avatar de jpint  
Fecha de Ingreso: junio-2012
Ubicación: Ciudad Real - España
Mensajes: 97
Antigüedad: 11 años, 10 meses
Puntos: 12
Respuesta: Dudas de como integrar html y php

Tienes que añadirle la siguiente cabecera a la función mail:

Código PHP:
$headers "Content-type:text/html;charset=UTF-8";
$success = @mail($EmailTo$Subject$Body$headers); 
Para más información, puedes echarle un vistazo a este tutorial: http://www.w3schools.com/php/func_mail_mail.asp

Además, si me permites darte un consejo, para concatenar código html en variable php, puedes jugar con las comillas dobles y simples, por ejemplo así:

Código PHP:
$Body .= '<p style="color: black;margin: 0;padding: 0">Please send to us: </p>\n';
$Body .= '<p style="color: black;margin: 0;padding: 0">* Anglers number </p>\n';
$Body .= '<p style="color: black;margin: 0;padding: 0">* Anglers names </p>\n';
$Body .= '<p style="color: black;margin: 0;padding: 0">* Fishing time </p>\n';
$Body .= '<p style="color: black;margin: 0;padding: 0">* Booking form </p>\n'
  #4 (permalink)  
Antiguo 28/07/2015, 07:19
Avatar de TIExpert  
Fecha de Ingreso: mayo-2015
Ubicación: Venezuela
Mensajes: 167
Antigüedad: 8 años, 11 meses
Puntos: 17
Respuesta: Dudas de como integrar html y php

Hola
Cita:
Además, si me permites darte un consejo, para concatenar código html en variable php, puedes jugar con las comillas dobles y simples, por ejemplo así:
Ciertamente es válido combinar comillas doble y simples, sin embargo el rendimiento al cargar la página se ve afectado. Es más optimo (según lo que he leído) utilizar el . para concatenar ó la barra invertida \ como lo esta haciendo el amigo.

Saludos
__________________
Mas de 20 años de experiencia en soporte de plataforma TI para empresas.

Etiquetas: dudas, formulario, html, integrar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:22.