ukweb Posted March 31, 2010 Share Posted March 31, 2010 Hi I can't see anything wrong with the code, and I've run out of ideas why the message when delivered is always blank. The attachment works fine though. The code is below, ANY ideas would be welcomed! if ($_POST['a'] == 'send_mail') { // Variables $action['to'] = '[email protected]'; $action['from'] = $_POST['email']; $action['name'] = $_POST['name']; $action['subject'] = $_POST['subject']; $action['num'] = md5(time()); $action['message'] = $_POST['message']; $action['html_message'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Email Message</title> <style type="text/css"> <!-- #wrapper { width: 550px; margin: 0 auto; } body { font-family: Verdana, Geneva, sans-serif; font-size: 11px; } h1, h2, h3, p { margin: 0px; padding-top: 5px; padding-bottom: 5px; color: #231F20; } h1, h2, h3 { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; color: #E52546; } --> </style> </head> <body> <div id="wrapper"> <h1>Message Received via the Web Site</h1> <p>Message Received from '.$action['name'].' ('.$action['email'].')</p> <p>Subject: '.$action['subject'].'</p> <h2>'.$action['name'].' Said:</h2> <p>'.$action['message'].'</p> </div> </body> </html>'; if ($_FILES) { // Set Paths and Variables $action['upload_path'] = 'uploads/email_attachments'; $action['upload'] = $_FILES['attachment']; $action['filename'] = basename($action['upload']['name']); $action['fp'] = fopen($action['upload']['tmp_name'], "rb"); $action['file'] = fread($action['fp'], $action['upload']['size']); $action['file'] = chunk_split(base64_encode($action['file'])); } // Headers $action['headers'] = "From: ".$action['name']."<".$action['email'].">\r\n"; $action['headers'] = "Reply-To: ".$action['name']."<".$action['email'].">\r\n"; $action['headers'] .= "MIME-Version: 1.0\r\n"; $action['headers'] .= "Content-Type: multipart/mixed; "; $action['headers'] .= "boundary=".$action['num']."\r\n"; $action['headers'] .= "--".$action['num']."\r\n"; $action['headers'] .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; $action['headers'] .= "X-Mailer: PHP v".phpversion()."\r\n"; $action['headers'] .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $action['headers'] .= "Content-Transfer-Encoding: 8bit\r\n"; $action['headers'] .= "".$action['html_message']."\n"; $action['headers'] .= "--".$action['num']."\n"; // Headers for Attachment if ($_FILES) { $action['headers'] .= "Content-Type:".$action['upload']['type']." "; $action['headers'] .= "name=\"".$action['filename']."\"r\n"; $action['headers'] .= "Content-Transfer-Encoding: base64\r\n"; $action['headers'] .= "Content-Disposition: attachment; "; $action['headers'] .= "filename=\"".$action['filename']."\"\r\n\n"; $action['headers'] .= "".$action['file']."\r\n"; $action['headers'] .= "--".$action['num']."--"; } @mail($action['to'], $action['subject'], $action['message'], $action['headers']); fclose($action['fp']); } Link to comment https://forums.phpfreaks.com/topic/197122-sending-html-email-with-php-but-message-is-always-blank-aaaggghhh/ Share on other sites More sharing options...
zeodragonzord Posted March 31, 2010 Share Posted March 31, 2010 Did you mean to use $action['html_message'] instead of $action['message'] on the mail()? Link to comment https://forums.phpfreaks.com/topic/197122-sending-html-email-with-php-but-message-is-always-blank-aaaggghhh/#findComment-1034760 Share on other sites More sharing options...
ukweb Posted March 31, 2010 Author Share Posted March 31, 2010 Did you mean to use $action['html_message'] instead of $action['message'] on the mail()? Hi Yea meant it to be coded the way it is, basically in the function, the $action['message'] is the plain-text email, and the $action['html_message'] is the HTML version, which is returned in the headers. I have a feeling it is something to do with the attached file; when I have the messages generated sent to my mobileme account, it displays the html email and a load of random characters at the end which i presume is the attachment as it changes if I attach a different attachment. needless to say it is winding me up no end! Link to comment https://forums.phpfreaks.com/topic/197122-sending-html-email-with-php-but-message-is-always-blank-aaaggghhh/#findComment-1034808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.