note 124702 added to function.mail

From: Date: Mon, 10 Feb 2020 05:47:30 +0000
Subject: note 124702 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-214074@lists.php.net to get a copy of this message
Sending mail with attachments function sendMail( $mailTo, $message, $subject = "Your Subject", $fromMail = "your@emialaddress.com", $fromName = "from sender", $replyTo = "no-reply", $filePath = "path" ) { $LE = "\r\n"; $uid = md5(uniqid(time())); $withAttachment = ($filePath !== NULL && file_exists($filePath)); if($withAttachment){ $fileName = basename($filePath); $fileSize = filesize($filePath); $handle = fopen($filePath, "r"); $content = fread($handle, $fileSize); fclose($handle); $content = chunk_split(base64_encode($content)); } $header = "From: ".$fromName." <".$fromMail.">$LE"; $header .= "Reply-To: ".$replyTo."$LE"; $header .= "MIME-Version: 1.0$LE"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"$LE$LE"; $header .= "This is a multi-part message in MIME format.$LE"; $header .= "--".$uid."$LE"; $header .= "Content-type:text/html; charset=UTF-8$LE"; $header .= "Content-Transfer-Encoding: 7bit$LE$LE"; $header .= $message."$LE$LE"; if($withAttachment){ $header .= "--".$uid."$LE"; $header .= "Content-Type: application/octet-stream; name=\"".$fileName."\"$LE"; $header .= "Content-Transfer-Encoding: base64$LE"; $header .= "Content-Disposition: attachment; filename=\"".$fileName."\"$LE$LE"; $header .= $content."$LE$LE"; $header .= "--".$uid."--"; } return mail($mailTo, $subject, "", $header); } ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 133.237.7.79) ---- Manual Page -- http://php.net/manual/en/function.mail.php Edit -- https://master.php.net/note/edit/124702 Del: integrated -- https://master.php.net/note/delete/124702/integrated Del: useless -- https://master.php.net/note/delete/124702/useless Del: bad code -- https://master.php.net/note/delete/124702/bad+code Del: spam -- https://master.php.net/note/delete/124702/spam Del: non-english -- https://master.php.net/note/delete/124702/non-english Del: in docs -- https://master.php.net/note/delete/124702/in+docs Del: other reasons-- https://master.php.net/note/delete/124702 Reject -- https://master.php.net/note/reject/124702 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214074) next »