【发布时间】:2014-01-31 14:06:46
【问题描述】:
我的网站上有一个注册表单,完成后详细信息存储在 CSV 文件中,但我还想向用户发送一封确认电子邮件。问题是电子邮件到达空白,我所做的是创建了一个 template.php 文件,其中包含我要发送的电子邮件结构,在此模板结构中,我具有来自其他文件的功能,用于确定注册日期。 template.php 中的模板包含在一个函数中,我在 from_to_csv.php 中调用它作为 mail() atrebiutes 的一部分:
希望这是有道理的,你们理解我看看代码:
template.php:
<?php
function getMailContent(){
$subject = "OPES Academy- Workshop confirmation";
$message = "
<body style='background-color: #eeeeee; margin: 0 auto; font-family: 'lato',sans-serif'>
<table style='background-color:#ffffff' width='600' heigth='auto' cellspacing='0' cellpadding='0' align='center'>
<tr>
<td>
<table width='600' style='background-color: #5e8ab5;' align='center' cellpading='0' cellspacing='0'>
<tr>
<td>
<p style='padding-left: 20px;'><img src='http://opesacademy.com/emails/images/logo.png'
width='100' alt='Opes Academy'></p>
</td>
<td style='text-align: right; padding-right: 10px; color: #ffffff'>
KNOWLEDGE | WEALTH | POWER
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style='padding: 10px;'>
<h1 class='skinytxt text-center txtblue'>Thank you for reserving your place</h1>
<p> </p>
<p class='txt-white text-center'>Thanks for your registration, we will be looking forward to see you at the";
?>
<?php
require('helper.php');
echo ConvertDate( $_SESSION['date'] );
?>
<?php
$message.="
<p align='center'>Address: 6 Thomas More Square, London, E1W 1XZ</p>
</p>
<p class='txt-white text-center'>If you have any more questions we will be glad to help you, just call us on 020 3675 9000 or email us on
support@opesacademy.com</p>
</td>
</tr>
</table>
<table width='600' style='background-color: #5e8ab5;' align='center' cellpading='0' cellspacing='0'>
<tr>
<td>
<p style='padding-left: 10px; padding-right: 10px; font-size: 10px'>Trading and investing often
involves a very high degree of risk. Past results are
not indicative of future returns and financial instruments can go down as well as up
resulting
in you receiving less than you invested. Do not assume that any recommendations, insights,
charts, theories, or philosophies will ensure profitable investment. Spread betting, trading
binary options and CFD's carry a high risk to your capital, can be very volatile and prices
may
move rapidly against you. Only speculate with money you can afford to lose as you may lose
more
than your original deposit and be required to make further payments. Spread betting may not
be
suitable for all customers, so ensure you fully understand the risks involved and seek
independent advice if necessary</p>
</td>
</tr>
</table>
</body>";
$headers = "Content-type: text/html\r\n";
return compact($subject, $message, $headers);
}
?>
form_to_csv.php:
$to = $data['email'];
require('template.php');
$mailContent = getMailContent();
//csv
if(@$_POST['land']=='fw'){
$path='/home/content/24/12131124/html/files/Admin/CSV_Binary/';
$fName=$path.'free_workshop-'.date( "F_j_Y" ).".csv";
//mail($to, $subject, $message, $headers,"-f info@opesacademy.com");
mail($to, $mailContent['subject'], $mailContent['message'], $mailContent['headers'],"-f info@opesacademy.com");
}
$to 变量包含用户在表单中输入的电子邮件.....
【问题讨论】:
-
您是否尝试在浏览器窗口中打印
template.php的输出? -
在我看来你已经用你自己的
mail()函数重新声明了 PHP 的mail()函数。这不应该引发关于尝试重新声明mail的错误吗? -
没有错误,只是电子邮件我空白,但如果我将电子邮件模板代码复制并粘贴到 form_to_csv 中。 php它的工作原理