อันนี้ function ที่ผมใช้ส่งเมลล์คับ
function mail_html($to,$subject,$message){
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=tis-620\n";
$headers .= "To: $to\n";
$headers .= "From: user@domain.com <user@domain.com>\n";
$subject = str_replace('\"', '"', $subject); //fix quotation mark problem for head and body
$subject = str_replace("\'", "'", $subject);
$message = str_replace('\"', '"', $message);
$message = str_replace("\'", "'", $message);
if(mail($to, $subject, $message, $headers)){
return true;
}else{return false;}
}
อันนี้เป็น HTML ที่ผมจะส่งไป ผมจะ assign ค่าโดยใช้ heredoc.syntax น่ะคับ จะได้ไม่ต้องไล่ใส่ escape ให้ยุ่งยากน่ะคับ
// heredoc.syntax for easy html variable
$body = <<<HTML
<p>$htmlbody</p>
<a href="http://domain.com/?id=12&cat=34">$anchortext</a>
HTML;
ส่งเมลล์แล้วทุกอย่างปกติ ยกเว้น string ตั้งแต่ ampersand (&) ไป หายเกลี้ยงเลย
ผมต้องจำใจไม่ใส่ลิ้งค์ไปก่อน รอความหวัง เข้าไปหาตามบอร์ด php อย่าง phpfreaks มันดันล่มวันนี้อีก (php error ทั้งหน้าเลย ไม่นึกว่าโปรๆ อย่าง phpfreaks จะพลาดได้เหมือนกัน)