2016-08-01 79 views
1

你好,我创建了一个程序,可以用icalendar发送邮件。但在描述中,Gmail的一部分看起来像我想要实现的相同的HTML代码。我怎样才能将html代码写入本节?或者至少我想学习如何使用新行(\n)。它也没有读新行......谢谢。如何将Html代码或 n写入Gmail的描述中? PHP

$cal_uid = date('Ymd').'T'.date('His')."-".rand()."@mydomain.com"; 


    $mime_boundary = "----Meeting Booking----".md5(time()); 
    $headers .= "MIME-Version: 1.0\n"; 
    $headers = "From: ".$from_name." <".$from_address.">\n"; 
    $headers .= "Reply-To: ".$from_name." <".$from_address.">\n"; 


    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; 
    $headers .= "Content-class: urn:content-classes:calendarmessage\n"; 


    $message .= "--$mime_boundary\n"; 
    $message .= "Content-Type: text/html; charset=UTF-8\n"; 
    $message .= "Content-Transfer-Encoding: 8bit\n\n"; 

    $message .= "<html>\n"; 
    $message .= "<body>\n"; 
    $message .= '<p>Merhaba '.$firstname.' '.$lastname.',</p>'; 
    $message .= $meeting_name;  
    $message .= "</body>\n"; 
    $message .= "</html>\n"; 

    $message .= "--$mime_boundary\n"; 


$ical = 'BEGIN:VCALENDAR 
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN 
VERSION:2.0 
METHOD:PUBLISH 
BEGIN:VEVENT 
ORGANIZER:MAILTO:'.$from_address.' 
DTSTART:'.$dtstart.' 
DTEND:'.$dtend.' 
LOCATION:'.$meeting_location.' 
TRANSP:OPAQUE 
SEQUENCE:0 
UID:'.$cal_uid.' 
DTSTAMP:'.$todaystamp.' 
DESCRIPTION:'.$meeting_description.' 
SUMMARY:'.$subject.' 
PRIORITY:5 
CLASS:PUBLIC 
END:VEVENT 
END:VCALENDAR'; 

    $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf-8\n'; 
    $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n'; 
    $message .= "Content-Transfer-Encoding: 8bit\n\n"; 
    $message .= $ical;    

    //SEND MAIL 
    $mail_sent = @mail($email, $subject, $message, $headers); 

    if($mail_sent)  { 
     return true; 
    } else { 
     return false; 
    } 

} 

回答

0

试试这个源

$subject = 'Website Change Request'; 

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n"; 
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n"; 
$headers .= "CC: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

了解更多关于Send email with HTML template PHP

0

你需要<br>标签,而不是 您可以转换您的字符串\n\r\n<br>使用nl2br($string) 检查文档here