I'm trying to send an HTML email with PHP. The body currently looks like this:
$body = "Hello," . "<br />" . "<br />" . "We sent you an e-mail to confirm your account has been "
. "created." . "<br />" . "<br />" . "Thank you!";
Would that properly separate the lines? When I declare my headers, would I also need to use the same format for line breaking?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: donotreply@webmaster.net";
Would I have to switch those new lines at the end of each header from "\\r\\n"
to "<br />"
?
Is better using library but to have an idea try this:
function sendemail( $to, $from, $subject, $title, $html, $cc = "", $bcc = "" )
{
$message = "\n";
$message .= "<!doctype html><html><head><title>$title</title></head><body>";
$message .= $html;
$message .= "</body></html>";
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: $from \r\n";
$headers .= "Reply-To: $from \r\n";
$headers .= ( $cc != "" ) ? "Cc: $bcc \r\n" : "";
$headers .= ( $bcc != "" ) ? "Bcc: $bcc \r\n" : "";
return mail( $to, $subject, $message, $headers, "" );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.