1

I am using mail() function of PHP, following is my code;

$to = "info@abc.com";
$subject = "Application for Job";
$attachment =chunk_split(base64_encode(file_get_contents($_FILES['attachresume']['tmp_name'])));
$filename = $_FILES['attachresume']['name'];

$boundary = md5(date('r', time()));

$headers = "From: info@xyz.com\r\nReply-To:  info@xyz.com";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

$message = "Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
<strong>Candidate Name :</strong> ".$candidatename."<br>
$message .="--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment $attachment --_2_$boundary--";

mail($to,$subject,$message,$headers);

But I dont know why, in email I am only getting attachment, I am not getting candidate name. I mean html contents.

Ahmed Syed
  • 1,179
  • 2
  • 18
  • 44
  • 1
    Better to use phpMailer. It make work with emails much more easier – Vasiliy vvscode Vanchuk May 13 '15 at 12:38
  • 2
    Possible duplicate of [Send attachments with PHP Mail()?](http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail) – Cayce K May 13 '15 at 12:39
  • Use a library. Try [SwiftMailer](http://swiftmailer.org/) or [PHPMailer](https://github.com/PHPMailer/PHPMailer). They take care of the technical details, you can focus on the business goals. – axiac May 13 '15 at 12:48
  • @Gunaseelan, no, I didn't missed it. – Ahmed Syed May 13 '15 at 13:01
  • @Gunaseelan you don't need to concatenate PHP variables, if you are using `"How are you $variable"`. you can do it when you are using `'How are you'.$variable` – Ahmed Syed May 14 '15 at 06:16

1 Answers1

0

I am moving to PHPMailer and I am using this code,

if (isset($_FILES['uploaded_file']) &&
    $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
                         $_FILES['uploaded_file']['name']);
}

for attachment.

Ahmed Syed
  • 1,179
  • 2
  • 18
  • 44