Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 467k

no email gets send

Mar 9 2023 4:40 PM

Hi Team

I am not getting any email when i try to send 3 attachments to the user, i dont know what could be the reason for this and need some help.

$attachement = array();
$attachement['data'][0] = 'pdfdata'; // Pass PDF content with  base64_encode
$attachement['data'][1] = 'tpPdfdata';

$attachement['name'][0] = 'sample1.pdf';
$attachement['name'][1] = 'sample2.pdf';
$attachement['name'][2] = 'sample3.pdf';

 function send($to, $from, $subject, $message, $cc, $attachement = '') {
	
	$mail_header = "[email protected]: $from\n";
	if(isset($cc)) {
		$mail_header.="Cc:$cc\n";
	}
	
	$mail_header.= "Reply-To:[email protected]\n";
	$mail_header.="MIME-Version:1.0";
	
	// boundary
	$semi_rand = md(time());
	$boundary = "==Multipart_Boundary_x{$semi_rand}x";
	
	
	// headers for attachement
	$mail_header.="\n". "Content-Type : multipart/mixed;\n" . " boundary=\"{$boundary}\"";
	
	// multipart boundary
	
	$message = "--{$boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n".
	"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
	
	// preparing attachements
	if(count($attachement) > 0) {
		for($i =0; $i < count($attachement); $i++) {
			$message .= "--{$boundary}\n";
			$data = $attachement['data'][$i];
			$message .= "Content-Type:application/octet-stream; name=\"" . $attachement['name'][$i] . "\"\n".
						"Content-Disposition: attachment;\n" . " filename=\"" . $attachement['name'][$i] . "\"; size=" . filesize($attachement['name'][$i]) . ";\n" .
                        "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
		}
	}
	$message .="--{$boundary}--";
	return mail($to, $subject, $message,$mail_header);
	
}

 


Answers (2)