2
Answers

no email gets send

Guest User

Guest User

2y
699
1

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 = ": $from\n";
	if(isset($cc)) {
		$mail_header.="Cc:$cc\n";
	}

	$mail_header.= "\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);

}
PHP
Answers (2)
0
Satya Karki

Satya Karki

9 56.7k 3.6m 2y

Hi,
Gmail has a limitation of file attachments to 25MB. Check your file size and try with a lower size. If you need to send the large file, I think you can upload it to GDrive and share the file link in the email body. For that check, below thread.

https://stackoverflow.com/questions/59242165/c-sharp-sending-gmail-with-uploading-large-file-on-google-drive-attachment

0
Rajeesh Menoth

Rajeesh Menoth

67 27.1k 2.7m 2y

Hi,

Try to validate the size of the attachments ( maximum 25 MB). If you are getting mail for a single attachment then the problem should be the size limit.