I'm sending letter with attachment via PHP mail() function, and it works without any errors emerging in process. Message goes right to the receiver with all text intact. The problem is that attachments (PDF and image) I send in message are OK if I send message to GMail address, but they're getting corrupted if I send message to other mail (I tried Mail.ru and some site mail). If I forward message to GMail, they're still corrupted and cannot be open. However, if I forward not-corrupted message from GMail to other mail address, files are fine. How can it possibly be, if messages are exactly the same?
I had the same trouble using the mail() function, my advice will be to use PHPMailer and sending the emails via SMTP.
Here is a small code snippet using PHPmailer:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtpserver.com'; // Specify main SMTP server. If you dont have one us GMAL or mandrill
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@youremail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from@youremail.com', 'Mailer');
$mail->addAddress('joe@youremail.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@youremail.com'); // Name is optional
$mail->addReplyTo('info@youremail.com', 'Information');
$mail->addCC('cc@youremail.com');
$mail->addBCC('bcc@youremail.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}