PHP mail function


#1

Hello Team PHP,

I’m having a problem with the PHP mail function which I’ve used successfully many times previously. I am sending a PDF attachment with the email. It does send the attachment normally BUT it always has a second text file attachment that I don’t believe I’m sending. The file is always 127 bytes and titled 'UntitledAttachment00xxx.txt.

I’m sure that I’m missing something but I’ve been over it a hundred times and don’t see anything.

Thanks in advance for the help

Here is the code snippit:

[php]<?php

$to = $email1;

$v2=$_SESSION[‘RJEmail’];
$from = $_SESSION[‘RJEmail’];
$subject=“Online Application Submission - “.$row_AppData[‘LastName’].’, '.$row_AppData[‘FirstName’];
$mime_boundary=”==Multipart_Boundary_x”.md5(mt_rand()).“x”;
$headers = “From: “.$_SESSION[‘RJEmail’].” \r\n”;
$headers .= “CC: “.$email2.”, “;
$headers .= “MIME-Version: 1.0\r\n” .“Content-Type: multipart/mixed;\r\n” .” boundary=”{$mime_boundary}"";

$message = “Attached please find an online employment application for your company. \n\n\n



You may review and approve all applicants by visiting:



http://www.abcclientservices.com/\n\n\n



THANK YOU!\n\n”;

$message .= “This is a multi-part message in MIME format.\n\n” .
“–{$mime_boundary}\n” .
“Content-Type:text/html; charset=“iso-8859-1”\n” .
“Content-Transfer-Encoding: 7bit\n\n” .
$message . “\n\n”;
$message .= “–{$mime_boundary}\n”;
$message .= “–{$mime_boundary}\n”;

unset($files);

$fname = array();
$files[0] = $fn;
$fname[0]=str_replace (" ", “”, $files[0]);

// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],“rb”);
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$b=$fname[$x];
$message .= “Content-Type: {“application/octet-stream”};\n” . " name="$files[$x]"\n" .
“Content-Disposition: attachment;\n” . " filename="$b"\n" .
“Content-Transfer-Encoding: base64\n\n” . $data . “\n\n”;
$message .= “–{$mime_boundary}\n”;
}

@mail($to, $subject, $message, $headers);[/php]


#2

I will give you the same advice I give everyone else. The mail function is notoriously unreliable. There are libraries and services that are far more suitable to utilize such as PHPMailer, SwiftMail, or MailGun.


#3

Thank you for the advice. I’ll check them out.