Buenas! Me han pasado este script de php para mandar el formulario de contacto a un mail:
<?php
// *******************
// BEGIN USER SETTINGS
//********************
$sendTo = "[email protected]";
$subject = "web form message";
$greeting = "new web form message";
// *****************
// END USER SETTINGS
// *****************
$details = "";
$passed = true;
foreach($_POST as $nam => $val) {
// any field that is required has a "-required" at the end of
// the name attribute and goes through JavaScript validation
$nam = str_replace("-required", "", $nam);
// clean possible injections
$val = str_replace(array("\r", "\n", "%0a", "%0d"), '', stripslashes($val));
// look for possible injections and break out of loop if found
if(strpos($val, "MIME-Version") !== false || strpos($val, "Content-Type") !== false) {
$passed = false;
break;
}
// grab the name and email and build everything else into the email body
switch($nam) {
case "name":
// strip out any "@" symbols for possible injections
$fromName = str_replace("@", "AT", $val);
$details .= $nam . ": " . $fromName . "\n";
break;
case "email":
$emailFrom = $val;
$details .= $nam . ": " . $emailFrom . "\n";
break;
default:
$details .= $nam . ": " . str_replace("@", "AT", $val) . "\n";
}
}
// send the email
if($passed) {
$details = $greeting . "\n\n" . ($details);
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=UTF-8\n";
$headers .= "From: " . $emailFrom . " <" . $fromName . ">\n";
$headers .= "Reply-To: " . $emailFrom . "\n";
mail($sendTo, $subject, $details, $headers);
}
// ***********
// END OF FILE
// ***********
El problema que tengo es que el mail no me reconoce los saltos de linea. Se que debo colocar un nl2br, pero no se donde, y consigo que me funcione!
Muchas gracias!