I have a rather large form that when filled out and submitted, I want the data to be formed into a CSV file and emailed to a specific email address.
Does anyone know if it is all at all possible to add a file upload function to the bottom of this form?
This is for a client and have just encountered limitations in my knowledge of PHP.
This is the code I am using:
<?php
if(isset($_POST['formSubmit'])) {
$email=$_REQUEST['email'];
$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];
$to = "***#***.co.uk";
$subject = "New application submission";
$message = "".
"Email: $email" . "\n" .
"First Name: $firstName" . "\n" .
"Last Name: $lastName";
//The Attachment
$varTitle = $_POST['formTitle'];
$varForname = $_POST['formForname'];
$varMiddlename = $_POST['formMiddlename'];
$varSurname = $_POST['formSurname'];
$varKnownas = $_POST['formKnownas'];
$varAdressline1 = $_POST['formAdressline1'];
$varAdressline2 = $_POST['formAdressline2'];
$varAdressline3 = $_POST['formAdressline3'];
$varAdressline4 = $_POST['formAdressline4'];
$varAdressline5 = $_POST['formAdressline5'];
$varPostcode = $_POST['formPostcode'];
$varTelephone = $_POST['formTelephone'];
$varMobile = $_POST['formMobile'];
$varEmail = $_POST['formEmail'];
$varApproval = $_POST['formApproval'];
$varothersurname = $_POST['formothersurname'];
$varsex = $_POST['formsex'];
$varninumber = $_POST['formninumber'];
$varjobtitle = $_POST['formjobtitle'];
$vardates = $_POST['formdates'];
$varresponsibilities = $_POST['formresponsibilities'];
$varjobtitle2 = $_POST['formjobtitle2'];
$vardates2 = $_POST['formdates2'];
$varresponsibilities2 = $_POST['formresponsibilities2'];
$varjobtitle3 = $_POST['formjobtitle3'];
$vardates3 = $_POST['formdates3'];
$varresponsibilities3 = $_POST['formresponsibilities3'];
$varwebsite = $_POST['formwebsite'];
$vartshirt = $_POST['formtshirt'];
$vardietary = $_POST['formdietary'];
$varpc = $_POST['formpc'];
$varmac = $_POST['formmac'];
$varlaptop = $_POST['formlaptop'];
$vardongle = $_POST['formdongle'];
$varediting = $_POST['formediting'];
$varsocial = $_POST['formsocial'];
$varphotography = $_POST['formphotography'];
$varfilming = $_POST['formfilming'];
$vartraining = $_POST['formtraining'];
$varexhibition = $_POST['formexhibition'];
$varspecial = $_POST['formspecial'];
$varhobbies = $_POST['formhobbies'];
$varphotography = $_POST['formphotography'];
$varfilming = $_POST['formfilming'];
$vartraining = $_POST['formtraining'];
$varexcel = $_POST['formexcel'];
$varbigpicture = $_POST['formbigpicture'];
$varcriminal = $_POST['formcriminal'];
$attachments[] = Array(
'data' => $data,
'name' => 'application.csv',
'type' => 'application/vnd.ms-excel' );
//Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//Add the headers for a file attachment
$headers = "MIME-Version: 1.0\n" .
"From: {$from}\n" .
"Cc: davidkirrage#gmail.com\n".
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
//Add a multipart boundary above the plain message
$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" .
$text . "\n\n";
//Add sttachments
foreach($attachments as $attachment){
$data = chunk_split(base64_encode($attachment['data']));
$name = $attachment['name'];
$type = $attachment['type'];
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" ;
$message = "--{$mime_boundary}--\n";
mail($to, $subject, $message, $headers);
header('Location: http://bigpictest.co.uk/thanks.php');
exit();
}
}
?>
There is no need to go to so much trouble.
The following will probably help:
$filename="directory/csvfile.csv"; //specify filename and path
$keys=array_keys($_POST); //get list of post keys
$file=fopen($filename,"w"); //open a csv file to write to;
fputcsv($file,$keys); //write post keys as first line of CSV file.
fputcsv($file,$_POST); //write post data as second line of csv file.
fclose($file); //close the file.
The csv file you need to attach is created thus. No need for all those variables.
I haven't checked your mail code. If you are having problems with attaching the file, please ask a different question about that (though there are doubtless answers here already)
Good luck!
I've done this in asp and asp.net but never had to do it with php (that is sending mail with attachments from the server).
The thing to understand is that when you submit the form, the data is being sent to be processed somewhere, lets say: FormProcessor which may be in a separate file or in the php page itself.
So when the FormProcessor receives the data, you can combine it or format it in anyway you like.
You would need access to the filesystem to create the file on the server.
Let's say that the function for sending email is in the FormProcessor scope.
You can use email headers to add the attachment when you define the email object.
This is one of my send email funcitons in php which I've modified to use as a sample here:
function FormProcessor_SendEmail($v){ // $v is an array containing the data to use for sending the email
// parameters = $v[0] = user email, $v[1] = business name,
// $v[2] = address, $v[3] = city, $v[4] = state, $v[5] = zip code,
// $v[6] = phone, $v[7] = message, $v[8] = service area
$eol = "\r\n";
$tb = "\t";
$stb = "\t\t";
// notify new registrant
$to = $v[0];
$subject = "This is the subject text";
$message = "Date : " . $this->prepare_new_timestamp() . ".<br /><br />" . $eol;
$message .= "Thank you for requesting more information about " . $this->get_sitename() . "<br /><br />" . $eol;
$message .= "We will be contacting you as soon as possible<br />" . $eol;
$message .= "with information that is tailored to your needs and interests.<br /><br />" . $eol;
$message .= "We have received the following information from you:<br /><br />" . $eol;
$message .= "Your Business Name: " . $v[1] . "<br />" . $eol;
$message .= "Business Address: " . $v[2] . "<br />" . $eol;
$message .= "City: " . $v[3] . "<br />" . $eol;
$message .= "State: " . $v[4] . "<br />" . $eol;
$message .= "Zip Code: " . $v[5] . "<br />" . $eol;
$message .= "Phone: " . $v[6] . "<br />" . $eol;
$message .= "Service Area: " . $v[8] . "<br />" . $eol;
$message .= "Message: <br />" . $v[7] . "<br /><br />" . $eol;
$message .= "If you have additional questions, please address them to: " . $this->get_support_email() . "<br />" . $eol;
$message .= "or by phone at: " . $this->get_support_phone() . "<br /><br />" . $eol;
$message .= "If you did not submit this request, please contact us and let us know<br />" . $eol;
$message .= "so that we may take the proper actions necessary.<br /><br />" . $eol;
$message .= "Sincerely,<br />" . $eol;
$message .= "The Team at " . $this->get_sitename() . "<br />" . $eol;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: sitename <' . $this->get_webmaster_email() . '>' . "\r\n";
$headers .= 'Cc: webmaster <' . $this->get_webmaster_email() . '>' . "\r\n";
mail($to,$subject,$message,$headers);
return 1;
}
It doesn't send an attachment, but I'm sure someone else on this site can help you find a better way.
Hope it helps.
Related
I would like to send an email with attachment.
I have no problem to send an email by using file path, but I prefer to set my attachment by using URL.
The email can sent successfully to my email without any attachment.
My PDF URL example: http://store/index.php/Store/GI/OrderID.pdf
Hope some can help me. Really Appreciate. Thank You.
Controller::
public function SendInvoice(){
$orderid = $this->uri->segment(3);
$result = $this->order->GetCustOrder($orderid);
unset($data);
$data = array(
$OrderID,
$result[0]->cust_id,
$result[0]->cust_name,
$result[0]->cust_email
);
$this->store_email->SendInvoiceToCust($data); //library
$this->session->set_flashdata('sent_email','Email has been sent to customer.');
redirect('Store/Index');
}
Library::
public function SendInvoiceToCust($data){
$message = "Dear Valued Customer, <br><br>Thank you for Purchased at Store. <br/><br/>Kindly refer the attachment to view your Invoice.";
//$attached_file = base_url(). 'index.php/Store/GI/' .$data[0]. '.pdf';
$form = base_url(). 'index.php/Store/GI/' .$data[0]. '.pdf';
$attachment = chunk_split(base64_encode($form));
$separator = md5(time());
$message .= "--" . $separator . PHP_EOL;
$message .= "Content-Type: application/octet-stream; name=\"\" . $data[0]. '.pdf'\"" . PHP_EOL;
$message .= "Content-Transfer-Encoding: base64" . PHP_EOL;
$message .= "Content-Disposition: attachment" . PHP_EOL . PHP_EOL;
$message .= $attachment . PHP_EOL . PHP_EOL;
$message .= "--" . $separator . "--";
$this->email->from('email#gmail.com', 'Store');
$this->email->to('email2#gmail.com');
$this->email->subject('Store INVOICE [Do not reply]');
$this->email->message($message);
$this->email->attach($attachment);
$this->email->send();
}
I cant comment yet but you should try setting content type and encoding the pdf.
The below is what I am currently using to send out an email with an attachement in codeigniter.
I have updated the response. This is currently how I am taking a pdf form and attaching it.
Its all done within the $message field with different content transfer and types being set.
$sender = "email#gmail.com";
$emails = "email2#gmail.com";
$subject = "Store INVOICE [Do not reply]";
$headers = "From: " . $sender . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$message = "";
$message = "--" . $separator . PHP_EOL;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"" . PHP_EOL;
$message .= "Content-Transfer-Encoding: 8bit" . PHP_EOL . PHP_EOL;
$message .= ($content = "Dear Valued Customer, <br><br>Thank you for Purchased at Store. <br/><br/>Kindly refer the attachment to view your Invoice.");
$message .= PHP_EOL . PHP_EOL;
$form = base_url(). 'index.php/Store/GI/' .$data[0]. '.pdf';
$attachment = chunk_split(base64_encode($form));
$separator = md5(time());
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: 7bit";
$message .= "--" . $separator . PHP_EOL;
$message .= "Content-Type: application/octet-stream; name=\"" . $data[0]. '.pdf'\"" . PHP_EOL;
$message .= "Content-Transfer-Encoding: base64" . PHP_EOL;
$message .= "Content-Disposition: attachment" . PHP_EOL . PHP_EOL;
$message .= $attachment . PHP_EOL . PHP_EOL;
$message .= "--" . $separator . "--";
$result = mail($emails, $subject, $message, $headers);
I use a simple section of php in my header to send the contents of a mysqli query (in this case a combination of three queries - 'ORDER' has the shipping details, 'CUSTOMER' contains the email details of the customer, and 'PRODLIST' has a list of products entered into the shopping cart)
I put together the following script, trying to collect the 'ORDER' details, and add a repeating region to add all the records in the 'PRODLIST' query.
It didn't work, and I was wondering if this is even possible, and if not is there a solution that will allow me to send a simple html email with the full details?
Both queries are working by the way, they are listed on screen in the actual web page, but the mail code is not responding, and causing the page not to load.
$to = 'RECIPIENT REMOVED';
$subject = "order from " . $ORDER->getColumnVal("CUSTOMER_NAME");
$headers = "From: " . $CUSTOMER->getColumnVal("EMAIL") . "\r\n";
$headers .= "Reply-To: ". $CUSTOMER->getColumnVal("EMAIL") . "\r\n";
$headers .= "BCC: info#sigwebdesign.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";$from = "<".$CUSTOMER->getColumnVal("EMAIL").">";
$message = '<html><body>';
$message .= '<p>The following order has been received</p>';
$message .= "Delivery Type: " . $ORDER->getColumnVal("DELIVERY_TYPE") . "<br>";
$message .= "<b>Delivery Date: " . $ORDER->getColumnVal("DELIVERY_DATE") . "<br><br><br></b>";
$message .= "Company: " . $ORDER->getColumnVal("CUSTOMER_NAME") . "<br>";
$message .= "Contact: " . $ORDER->getColumnVal("PLACED_BY") . "<br><br>";
$message .= "Address: " . $ORDER->getColumnVal("DELIVERY_ADDRESS") . "<br>";
$message .= "Address: " . $ORDER->getColumnVal("CITY") . "<br>";
$message .= "Address: " . $ORDER->getColumnVal("STATE") . "<br>";
$message .= "Address: " . $$ORDER->getColumnVal("ZIP") . "<br><br><br>";
while(!$PRODLIST->atEnd()) {
$message .= "ITEM: " . $PRODLIST->getColumnVal("GENUS")." ".$PRODLIST->getColumnVal("VARIETY") . "<br>";
$message .= "QTY: " . $PRODLIST->getColumnVal("QUANTITY") . "<br>";
$PRODLIST->moveNext();
}
$PRODLIST->moveFirst();
$message .= "Total Cost: " . $_SESSION['fullcost'] . "<br><br><br>";
$message .= "This price does not include shipping, and applicable taxes. <br> Your order will be processed, and a final confirmation will be sent to you by email or by phone. <br><br>";
$message .= '</html></body>';
mail($to,$subject,$message,$headers);
So I worked it out. I added an extra "$" in the coding, and it threw a whole big spanner in the works.
so the answer (note to self at least) is check check and triple check the code!
Text mail works fine but I want to attach file too.
Attachment is not working.
My code is:
<form method="post" enctype="multipart/form-data">
<input name="filepc" type="file" id="filepc" class="listEm" />
</form>
if (isset($_POST['submit'])) {
$attachments = '';
if (!empty($_FILES['filepc']['tmp_name'])) {
$attachments = array($_FILES['filepc']['name']);
}
headers = "From:" . $your_email . " < " . $email . ">" . "\r\n";
$headers .= "Reply - To:" . $ct_email . "\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$attachments."\"\r\n\r\n";
//$headers = "Bcc: someone#domain . com" . "\r\n";
$headers = "X - Mailer: PHP / " . phpversion();
mail($to , $subject , $msg , $headers,$attachments);
$successMsg = '<h5 style="color:red;">Sent successfully</h5>';
// }
}
Above code works but file is not attached. Please help me find the solution for this problem.
if(!empty($_FILES['resume']['name'])) {
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$tmp_name = $_FILES['resume']['tmp_name'];
$type = $_FILES['resume']['type'];
$file_name = $_FILES['resume']['name'];
$size = $_FILES['resume']['size'];
// Check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// Now Open the file for a binary read
$file = fopen($tmp_name,'rb');
// Now read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// Now we need to encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
$mybody = "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" .
$mybody . "\n\n";
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$mybody .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$bodys .= "$mybody <br>";
$subject = "Attachment";
$body = $body . $bodys;
mail($to, $subject, $body, $headers);
}
I'm trying to use a PHP email form I found online that supports attachments, with a bit of extra code, but it's not working, I get a message saying "Sent", but no emails (I checked spam already).
Here is the php file:
function multi_attach_mail($to, $subject, $message, $senderMail, $senderName, $files){
$from = $senderName." <".$senderMail.">";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
// preparing attachments
if(count($files) > 0){
for($i=0;$i<count($files);$i++){
if(is_file($files[$i])){
$message .= "--{$mime_boundary}\n";
$fp = #fopen($files[$i],"rb");
$data = #fread($fp,filesize($files[$i]));
#fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($files[$i])."\"\n" .
"Content-Description: ".basename($files[$i])."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($files[$i])."\"; size=".filesize($files[$i]).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $senderMail;
//send email
$mail = #mail($to, $subject, $message, $headers, $returnpath);
//function return true, if email sent, otherwise return fasle
if($mail){ return TRUE; } else { return FALSE; }
}
$message = "Customer Contact"
. "\n" . "Name: " . $_POST['fullName']
. "\n" . "Email: " . $_POST['email']
. "\n" . "Phone: " . $_POST['phone']
. "\n" . "Current Phone: " . $_POST['currentPhone']
. "\n" . "Address: " . $_POST['address']
. "\n" . "Retailer: " . $_POST['retailer']
. "\n" . "Product Type: " . $_POST['productType']
. "\n" . "Specific Item: " . $_POST['item']
. "\n" . "Purchase Date: " . $_POST['purchaseDate']
. "\n" . "Invoice Number: " . $_POST['invoiceNumber']
. "\n" . "Issue: " . $_POST['issue']
. "\n" . "How did the issue happen?: " . $_POST['how']
. "\n" . "When did the issue occur?: " . $_POST['when']
. "\n" . "Have you done anything to try correcting the issue?: " . $_POST['customerTry'];
$to = 'someEmail#gmail.com';
$from = $_POST['email'];
$from_name = $_POST['fullName'];
//attachment files path array
$files = $_FILES['files'];
$subject = 'Customer Contact From Service Form';
$html_content = $message;
//call multi_attach_mail() function and pass the required arguments
$send_email = multi_attach_mail($to,$subject,$html_content,$from,$from_name,$files);
//print message after email sent
echo $send_email?"<h1> Mail Sent</h1><br>".$message:"<h1> Mail not SEND</h1>";
My form looks like this:
<form NOVALIDATE action="processContact.php" enctype="multipart/form-data" id="claimsForm" method="post" name="claimsForm">
..lots of fields...
<div class="form-group">
<label class="control-label claimsForm-field-header" for="customerTry">Photos:</label>
<input type="file" id="files[]" name="files[]" multiple="multiple" />
</div>
<input class="green-btn" id="ss-submit" name="submit" type="submit" value="Submit">
</form>
The function came with the form I downloaded, so I don't think there is a problem with it. I've been playing around with the code and trying different things, but no luck (I'm not a PHP guy).
EDIT:
Based on the suggestion below, I tried using phpMailer, following the example they have, here is my php file now:
/**
* PHPMailer simple file upload and send example
*/
$msg = '';
$message = "Customer Contact"
. "\n" . "Name: " . $_POST['fullName']
. "\n" . "Email: " . $_POST['email']
. "\n" . "Phone: " . $_POST['phone']
. "\n" . "Current Phone: " . $_POST['currentPhone']
. "\n" . "Address: " . $_POST['address']
. "\n" . "Retailer: " . $_POST['retailer']
. "\n" . "Product Type: " . $_POST['productType']
. "\n" . "Specific Item: " . $_POST['item']
. "\n" . "Purchase Date: " . $_POST['purchaseDate']
. "\n" . "Invoice Number: " . $_POST['invoiceNumber']
. "\n" . "Issue: " . $_POST['issue']
. "\n" . "How did the issue happen?: " . $_POST['how']
. "\n" . "When did the issue occur?: " . $_POST['when']
. "\n" . "Have you done anything to try correcting the issue?: " . $_POST['customerTry'];
$to = 'murtorius#gmail.com';
$from = $_POST['email'];
$from_name = $_POST['fullName'];
//attachment files path array
$files = $_FILES['userfile'];
$subject = 'Customer Contact From Service Form';
if (array_key_exists('userfile', $_FILES)) {
// First handle the upload
// Don't trust provided filename - same goes for MIME types
// See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
// Upload handled successfully
// Now create a message
// This should be somewhere in your include_path
require 'php-mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom($from, $from_name);
$mail->addAddress($to, 'TEST');
$mail->Subject = $subject;
$mail->msgHTML($message);
// Attach the uploaded file
$mail->addAttachment($uploadfile, 'Photos');
if (!$mail->send()) {
$msg .= "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg .= "Message sent!";
}
} else {
$msg .= 'Failed to move file to ' . $uploadfile;
}
}
I changed the input file field name to 'userfile[]', but I get this:
Warning: sha1() expects parameter 1 to be string, array given in /home/zucora/service.zucora.com/processContact.php on line 35
Warning: move_uploaded_file() expects parameter 1 to be string, array given in /home/zucora/service.zucora.com/processContact.php on line 36
If I change the name to 'userfile' (without []) I get a blank screen and no email.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm not sure why but this has suddenly stopped sending out emails. I have tried to test the email server using mail("email#domain.com","test","test message"); and it sends it fine. I have a feeling something is wrong with my headers?
I have tried to send it with and without attachments but it is not working.
Any help would be greatly appreciated.
Thanks in advance!
<?php
extract($_POST);
$dir = '../uploads/';
$files_temp = scandir($dir, 1);
foreach ($files_temp as $key=>$value) {
if (strpos($value,$file_id) !== false) {
$files[] = $value;
}
}
$message = "";
$message .= "Firm: " . $_POST['firm'] . "\n";
$message .= "Attorney: " . $_POST['attorney'] . "\n";
$message .= "Main Contact: " . $_POST['main_contact'] . "\n";
$message .= "Phone: " . $_POST['phone'] . "\n";
$message .= "Cell: " . $_POST['cell'] . "\n";
$message .= "Fax: " . $_POST['fax'] . "\n";
$message .= "Address: " . $_POST['address'] . "\n";
$message .= "Email: " . $_POST['email'] . "\n";
$message .= "Court County: " . str_replace("_"," ",$_POST['court_county']) . "\n";
$message .= "Court Name: " . $_POST['court_name'] . "\n";
$message .= "Case Type: " . str_replace("_"," ",$_POST['case_type']) . "\n";
$message .= "Appearance Type: " . $_POST['appearance_type'] . "\n";
$message .= "Date: " . $_POST['date'] . "\n";
$message .= "Time: " . $_POST['time'] . "\n";
$message .= "Department: " . $_POST['department'] . "\n";
$message .= "Case Name: " . $_POST['case_name'] . "\n";
$message .= "Case Number: " . $_POST['case_number'] . "\n";
$message .= "Your Client: " . $_POST['your_client'] . "\n";
$message .= "Client Present: " . $client_present_text . "\n";
$message .= "What do you want the attorney to accomplish at this hearing?: " . $_POST['text1'] . "\n";
$message .= "Explain case background: " . $_POST['text2'] . "\n";
$message .= "Signature: " . $_POST['signature'] . "\n";
// email fields: to, from, subject, and so on
$to = "email#domain.com";
$from = "email#domain.com";
$subject ="Appearance form";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($dir.$files[$x],"rb");
$data = fread($file,filesize($dir.$files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = #mail($to, $subject, $message, $headers);
Looks like my code wasn't the problem. It was an issue with mailing it from info#mydomain.com. Changed $from variable to a gmail email address and it started sending emails again.