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 ??