note 125168 added to function.mail
| From: | pangz dot lab at gmail dot com | Date: | Mon, 06 Jul 2020 08:42:59 +0000 |
| Subject: | note 125168 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214835@lists.php.net to get a copy of this message | ||
* Sending email with attachment
function sendMail(
string $fileAttachment,
string $mailMessage = MAIL_CONF["mailMessage"],
string $subject = MAIL_CONF["subject"],
string $toAddress = MAIL_CONF["toAddress"],
string $fromMail = MAIL_CONF["fromMail"]
): bool {
$fileAttachment = trim($fileAttachment);
$from = $fromMail;
$pathInfo = pathinfo($fileAttachment);
$attchmentName = "attachment_".date("YmdHms").(
(isset($pathInfo['extension']))? ".".$pathInfo['extension'] :
""
);
$attachment = chunk_split(base64_encode(file_get_contents($fileAttachment)));
$boundary = "PHP-mixed-".md5(time());
$boundWithPre = "\n--".$boundary;
$headers = "From: $from";
$headers .= "\nReply-To: $from";
$headers .= "\nContent-Type: multipart/mixed;
boundary=\"".$boundary."\"";
$message = $boundWithPre;
$message .= "\n Content-Type: text/plain; charset=UTF-8\n";
$message .= "\n $mailMessage";
$message .= $boundWithPre;
$message .= "\nContent-Type: application/octet-stream;
name=\"".$attchmentName."\"";
$message .= "\nContent-Transfer-Encoding: base64\n";
$message .= "\nContent-Disposition: attachment\n";
$message .= $attachment;
$message .= $boundWithPre."--";
return mail($toAddress, $subject, $message, $headers);
}
* Sending email in html
function sendHtmlMail(
string $mailMessage = MAIL_CONF["mailMessage"],
string $subject = MAIL_CONF["subject"],
array $toAddress = MAIL_CONF["toAddress"],
string $fromMail = MAIL_CONF["fromMail"]
): bool {
$to = implode(",", $toAddress);
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'To: '.$to;
$headers[] = 'From: '.$fromMail;
return mail($to, $subject, $mailMessage, implode("\r\n", $headers));
}
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.166.36 (proxied: 133.237.7.91)
----
Manual Page -- http://php.net/manual/en/function.mail.php
Edit -- https://master.php.net/note/edit/125168
Del: integrated -- https://master.php.net/note/delete/125168/integrated
Del: useless -- https://master.php.net/note/delete/125168/useless
Del: bad code -- https://master.php.net/note/delete/125168/bad+code
Del: spam -- https://master.php.net/note/delete/125168/spam
Del: non-english -- https://master.php.net/note/delete/125168/non-english
Del: in docs -- https://master.php.net/note/delete/125168/in+docs
Del: other reasons-- https://master.php.net/note/delete/125168
Reject -- https://master.php.net/note/reject/125168
Search -- https://master.php.net/manage/user-notes.php