Php mail not working

Hi,
i have a form in which there are 4 fields,

  • Name
  • email_id
  • comments
  • file

and below is the code to send the mail with an attachment


<?php
// Read POST request params into global vars
$to       = "recpt[EMAIL="recpt@gmail.com"]@gmail.com[/EMAIL]";
$from     = $_POST['email_id'];
$username  = trim($_POST['Name']);
$subject  = $username."'s comments";
$message  = $_POST['comments'];
 
$fileatt      = $_FILES['file']['tmp_name'];
$fileatt_type = $_FILES['file']['type'];
$fileatt_name = $_FILES['file']['name'];
 
$headers = "From: " . $username   . "<webmaster@domain.com>

";
$headers .= "Reply-To: " . $from. "

";
$headers .= "Return-Path: <[COLOR=#0000ff]webmaster@domain.com[/COLOR]> 

";
 
if (is_uploaded_file($fileatt)) {
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
 
  $headers .= "
MIME-Version: 1.0
" .
              "Content-Type: multipart/mixed;
" .
              " boundary=\"{$mime_boundary}\"";
 
  $message = "This is a multi-part message in MIME format.

" .
             "--{$mime_boundary}
" .
             "Content-Type: text/plain; charset=\"iso-8859-1\"
" .
             "Content-Transfer-Encoding: 7bit

" .
             $message . "

";
 
  $data = chunk_split(base64_encode($data));
 
  $message .= "--{$mime_boundary}
" .
              "Content-Type: {$fileatt_type};
" .
              " name=\"{$fileatt_name}\"
" .
              //"Content-Disposition: attachment;
" .
              //" filename=\"{$fileatt_name}\"
" .
              "Content-Transfer-Encoding: base64

" .
              $data . "

" .
              "--{$mime_boundary}--
";
}
 
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
  echo "<p>Mail sent!</p>";
  echo $ok;
} else {
  echo "<p>Mail could not be sent. Sorry!</p>";
}
?>

this will not work if u give someid@gmail.com or someid@yahoo.com in email_id field of the form… It will work only if i give test@test.com in the email_id field of that form.

What is wrong in the code ?? :expressionless:

The headers seem messed up…

whats wrong with the headers ?? can u please suggest me …

Well, I don’t really know, but are you sure you’re supposed to do something like “Reply-To:” ? Here’s the mail function: http://us3.php.net/manual/en/function.mail.php.

Sorry I can’t be of much help right now…

When you try to set the From header as an domain that does not exist on the machine, the server on the recieving end knows it’s a fake and will block it in many cases.

You write very well, support youneoprene computer bags [url=http://www.cnprince.com/en/oem.html]neoprene Laptop computer bags [url=http://www.cnprince.com/en/oem.html]memory foam computer bags [url=http://www.cnprince.com/en/oem.html]memory foam Laptop computer bags