PHP email code and gmail attachment problem

hello every one,
I am using a following PHP code for getting request from my website contact us form. It is working fine and I am able to receive emails. The problem is if I use any gmail account the information is coming as attachment. First I thought it a gmail error but my friend receives email properly in gmail. Can any one verify what could be the problem. The code is below.


<?PHP

$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['Phone'];
$address=$_POST['Address'];


$comment=$_POST['Comment'];

# -=-=-=- MIME BOUNDARY

# -=-=-=- MAIL HEADERS
$to = "example@gmail.com";

$subject = Request from contact us form";
//$headers = 'From: '.$name.'<'.$email.">\\r\
"; 
$headers = "From: examplesite <webmaster@examplesite.com>\
";
$headers .= 'Reply-To: '.$email."\\r\
";
$headers .= "MIME-Version: 1.0\
";
$headers .= "Content-Type: multipart/alternative; boundary=\\"$mime_boundary\\"\
";

$message="Name :".$name."\
";
$message.="Eamil :".$email."\
\
";
$message.="telephone :".$phone."\
";
$message.="Address :".$address."\
\
";

$message.="comment :".$comment."\
";

# -=-=-=- SEND MAIL
$mail_sent = @mail( $to, $subject, $message, $headers );
//echo $mail_sent ? "Mail sent" : "Mail failed";
if($mail_sent)
{
header('Location:thanks.html');
}
else
{
header('Location:error.html');
}
?>


Hi
this line means the content is in html format.
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . "\r
";

if you have replaced
by <br> for the code below then it would have worked. Sorry for the late reply.


$message="Name :".$name."<br>";
$message.="Eamil :".$email."<br><br>";
$message.="telephone :".$phone."<br>";
$message.="Address :".$address."<br><br>";

team1504

Actually what “bishwadeepkc” mentioned worked. I replace the line with $headers .= ‘Content-type: text/html; charset=iso-8859-1’ . "\r
";. It solved the attachment problem but it made the text of email unformated. Like all the text were showing in one line. So I completely removed that line. Which solved the problem. I think this line was unnecessary. I hope this will clear it. :slight_smile:

Trafford,
Would u mind posting your solution because not only am i curious on what you did but also it would help anyone in the future reading this thread. :slight_smile:

Thanks in Advance,
Team 1504

hi, Thanks for pointing out the spelling mistake:). Actually I didn’t wrote this code I took this code from a website. So I really don’t know the reason behind using it.

Thanks bishwa, It solved the attachment problem but all the fields from the contact us form were showing in one line. So I totally removed this line from header and it solved that problem. Any way Thanks for the help. One again this forum has successful in solving my problem. Thanks to this great forum and their members.

hello,
well email is spelled wrong in this line:

$message.=“Eamil :”.$email."

";

Besides that i agree with bishwadeepkc, why are using the line
$headers .= “Content-Type: multipart/alternative; boundary=\”$mime_boundary\"
";

In other words, what is your reasoning behind it?

Hi trafford,
can you tell me why are you using this line.
$headers .= “Content-Type: multipart/alternative; boundary=\”$mime_boundary\"
";
you can use:
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . "\r
";
instead. I think this line is causing the problem and showing the attachment.

:slight_smile: got it. Thanks for solving the confusion