我用这段代码发送邮件。但是,当我将$标头和行添加到$ body时,它停止工作。任何人都可以支持我找到错误或错误吗?用php发送邮件
我将不胜感激支持。
<?PHP
// Email Address
$youremail = '[email protected]';
$memberemail = $_POST['email'];
// Register Form
if (isset($_POST['email']) && isset($_POST['name']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
// Detect & Prevent Header Injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ($_POST as $key => $val) {
if (preg_match($test, $val)) {
exit;
}
}
// Email Format
$body = "Hola! $_POST[name]. Gracias por solicitar tu inscripción. \n";
$body .= "Analizaremos tú solicitud y en caso de resultar positiva recibirás un correo de confirmación en las próximas 24 horas. \n\n";
$body .= "Tus datos de solicitud son: \r\n"
$body .= "============================ \r\n";
$body .= "Nombre: $_POST[name] \n";
$body .= "eMail: $_POST[email] \n";
$body .= "Empresa: $_POST[telephone] \n";
$body .= "Sector: $_POST[ticket] \n\n";
$body .= "Atentamente, \n";
$body .= "Staff \n\n";
$body .= "NOTA: Para culaquier duda sobre tu proceso de inscripción te recomendamos leer las preguntas frecuentes en el sito web del evento http://www.evento.com";
//Send email
$headers = "From: Staff <[email protected]>" . "\r\n" . "Bcc: [email protected]" . "\r\n";
mail("To:" . $memberemail , "Nuevo registro", $body, "From:" . $headers);
}
// Subscribe Form
if(isset($_POST['subscriber']) && filter_var($_POST['subscriber'], FILTER_VALIDATE_EMAIL)) {
$data = $_POST['subscriber'] . ";" . "\n";
$ret = file_put_contents('subscribers.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('Ouch! Al parecer hay un error.');
}
} else {
die('No se pueden enviar los datos.');
}
?>
为什么不只是使用http://www.tectite.com/formmailpage.php – KnightHawk 2014-10-31 16:13:44
Procura primero revisar ladocumentaciónoficial http://php.net/manual/en/function.mail.php,pero procura buscar otras opciones (libreríasu otros)... tu respuesta ya la dio @Fred -ii- – 2014-10-31 16:22:04
如果您已经看到我的回答,但它没有起作用,我在测试代码时发现了另一个问题,以确定它是否有效(它确实有效),还有一个缺失的分号。请重新载入我的答案以查看编辑。 – 2014-10-31 16:59:26