我正在尝试制作一个功能,保存我的配置数据,以便自动发送电子邮件。
数据来自textareas so $_POST,并放入此函数中。
我的保存功能不是保存\r\n字符,因此不会换行。所以当我发送一封电子邮件时,完整的消息在1个大字符串中,没有换行…
如果我打开文件,它是用空格保存的,而不是全部在一行上。
if ($_POST['gdwemail_obj']!="") { $gdwEConfig['gdwemail_obj'] = $_POST['gdwemail_obj']; }
if ($_POST['gdwemail_mes']!="") { $gdwEConfig['gdwemail_mes'] = $_POST['gdwemail_mes']; }
saveEConfig($gdwEConfig);
function saveEConfig($post) {
$gdw_conffile = 'components'.DS.'com_gdwformulaire'.DS.'included'.DS.'econfig.gdw.php';
$gdw_confopen = fopen($gdw_conffile,'w+');
$gdw_cfgput = '<?php';
$gdw_cfgput .= ' $gdwEconf = array(); ';
$gdw_cfgput .= ' $gdwEconf[\'gdwemail\'] = "'.$post['gdwemail'].'"; ';
$gdw_cfgput .= ' $gdwEconf[\'gdwemail_obj\'] = "'.$post['gdwemail_obj'].'"; ';
$gdw_cfgput .= ' $gdwEconf[\'gdwemail_mes\'] = "'.$post['gdwemail_mes'].'"; ';
$gdw_cfgput .= '?>';
if (!fwrite($gdw_confopen, $gdw_cfgput)) {
echo "<script> alert('ERROR: Can't save configuration file, please verify CHMOD access on \'administrator/components/com_ai/\' for write access.'); window.history.go(-1); </script>\n";
exit;
}
fclose($gdw_confopen);
}输出如下所示:
<?php $gdwEconf = array(); $gdwEconf['gdwemail'] = "j.robidas@geantduweb.ca"; $gdwEconf['gdwemail_obj'] = "Réservation pour le cours {courschoisi} a été reçus"; $gdwEconf['gdwemail_mes'] = "Cher {nomdemandeur},
Votre demande de réservation a été reçus avec succès.
Information pour votre sélection:
{courschoisi}
{dateheurechoisi}
Merci
L'équipe de Belle vie de chien"; ?>发布于 2011-02-02 05:04:40
因为您实际上没有将\r\n包含在$gdw_cfgput .=中...台词。
发布于 2011-02-02 05:04:55
您没有要求它在您的$gdw_cfgput字符串中插入任何换行符。
$gdw_cfgput = '<?php';
$gdw_cfgput .= "\r\n";
$gdw_cfgput .= ' $gdwEconf = array(); ';请注意双引号,它告诉PHP将\r\n解释为换行符。
发布于 2011-02-02 05:07:29
您的文件不包含换行符,因为您没有指定任何换行符。您组装$gdw_cfgput,但不附加任何. "\r\n";。如果你想添加它,你可以使用. PHP_EOL; btw。
但是,如果您使用var_export()生成输出文件,则是一种更好的选择。看起来你有一个相干的数组,var_export会简化它的输出。
$config = var_export($_POST, true);
fwrite($f, "<?php\n\n\$gdwEconf = $config;\n?>");https://stackoverflow.com/questions/4867856
复制相似问题