Saturday, 15 May 2010

email - sender mail with php -



email - sender mail with php -

i utilize code send mail. stopped working when added $headers , lines $body. can back upwards me in finding error or errors?

i appreciate support.

<?php // email address $youremail = 'correo@correo.com'; $memberemail = $_post['email']; // register form if ( isset($_post['email']) && isset($_post['name']) && filter_var($_post['email'], filter_validate_email) ) { // observe & prevent header injections $test = "/(content-type|bcc:|cc:|to:)/i"; foreach ( $_post $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 united nations 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 <contacto@evento.com>" . "\r\n" . "bcc: admin@evento.com" . "\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 united nations error.'); } } else { die('no se pueden enviar los datos.'); } ?>

change $body, "from:" . $headers) $body, $headers)

you have from: in:

$headers = "from: staff <contacto@evento.com>"...

plus noted in comments, alter , remove "to:" .

mail( "to:" . $memberemail , "nuevo registro", $body, "from:" . $headers);

to

mail($memberemail, "nuevo registro", $body, $headers);

mail automatically sets first parameter recipient to:

however, may have wanted utilize $youremail first parameter , $memberemail from:, because mail service sent person sent email, allow decide on that.

consult manual:

http://php.net/manual/en/function.mail.php

edit:

there missing semi-colon in next line (which overlooked) before testing code:

body .= "tus datos de solicitud son: \r\n" ^ missing semi-colon

add it

body .= "tus datos de solicitud son: \r\n";

if error reporting set, have seen next parse/syntax error:

parse error: syntax error, unexpected '$body' (t_variable) in /server/path/file.php on line (number)

when php signals parse error on line number, on line "before" that, , not actual line number itself.

if see parse error on line 22, fault on line 21, , not 22.

add error reporting top of file(s) help find errors.

<?php error_reporting(e_all); ini_set('display_errors', 1); // rest of code

sidenote: error reporting should done in staging, , never production.

php email

No comments:

Post a Comment