0
我有一個網站與繆斯和我以前接觸表單控件時,它會生成一個PHP腳本,用下面的函數發送的形式產生人體消息:
function get_email_body($subject, $heading, $fields, $resources) {
$message = '';
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$message .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$message .= '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><title>' . encode_for_form($subject) . '</title></head>';
$message .= '<body style="background-color: #ffffff; color: #000000; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: helvetica, arial, verdana, sans-serif;">';
$message .= '<h2 style="background-color: #eeeeee;">' . $heading . '</h2>';
$message .= '<table cellspacing="0" cellpadding="0" width="100%" style="background-color: #ffffff;">';
$sorted_fields = array();
foreach ($fields as $field => $properties) {
// Skip reCAPTCHA from email submission
if ('recaptcha' == $properties['type'])
continue;
array_push($sorted_fields, array('field' => $field, 'properties' => $properties));
}
// sort fields
usort($sorted_fields, 'field_comparer');
foreach ($sorted_fields as $field_wrapper)
$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>' . encode_for_form($field_wrapper['properties']['label']) . ':</b></td><td>' . get_form_field_value($field_wrapper['field'], $field_wrapper['properties'], $resources, true) . '</td></tr>';
$message .= '</table>';
$message .= '<br/><br/>';
$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) . '</div>';
$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_by'], encode_for_form($_SERVER['REMOTE_ADDR'])) . '</div>';
$message .= '</body></html>';
return cleanup_message($message);
}
此功能使主機不會發送電子郵件消息,但如果我用$_SERVER['SERVER_NAME']
和$_SERVER['REMOTE_ADDR']
註釋這些行,則發送消息沒有問題。
//$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) . '</div>';
//$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_by'], encode_for_form($_SERVER['REMOTE_ADDR'])) . '</div>';
腳本也產生這些標題行:
function get_email_headers($to_email, $form_email) {
$headers = 'From: ' . $to_email . PHP_EOL;
$headers .= 'Reply-To: ' . $form_email . PHP_EOL;
//$headers .= 'X-Mailer: Adobe Muse CC 2015.1.1.343 with PHP' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
return $headers;
}
我真的搜索關於它的信息在繆斯論壇等,但我想知道爲什麼這些$_SERVER['SERVER_NAME']
和$_SERVER['REMOTE_ADDR']
,使發送崩潰。主機不會引發任何錯誤或警告消息。
非常感謝。
接聽評論:
function cleanup_message($message) {
$message = wordwrap($message, 70, "\r\n");
return $message;
}
function encode_for_form($text) {
$text = stripslashes($text);
return htmlentities($text, ENT_QUOTES, 'UTF-8');// need ENT_QUOTES or webpro.js jQuery.parseJSON fails
}
sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME']))
打印像 「從網站anubbe.com已發送」 的字符串。它來自一個數組。
你有錯誤報告和你達到的功能(之前'回報cleanup_message($消息)輸出的東西到底;'什麼呢? 'sprintf($ resources ['submitted_from'],encode_for_form($ _ SERVER ['SERVER_NAME']))'outputs? – Justinas
我已更新問題以回答您的評論。 –