-1

我希望根据他们以网站形式使用的选择发送动态电子邮件。目前我有:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = isset($_POST['name']) ? htmlentities($_POST['name']) : '';
    $more_info = isset($_POST['more_info']) ? htmlentities($_POST['more_info']) : '';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Hello <hello@example.com>' . "\r\n";
$to_email = 'Me <hello@me.com>';

$subject_email = 'Test Contact';

if ($more_info == "A") { $mail_content = file_get_contents('http://www.example.com/mail/a.php');}
if ($more_info == "B") { $mail_content = file_get_contents('http://www.example.com/mail/b.php');}
if ($more_info == "C") { $mail_content = file_get_contents('http://www.example.com/mail/c.php');}
if ($more_info == "D") { $mail_content = file_get_contents('http://www.example.com/mail/d.php');}
if ($more_info == "E") { $mail_content = include('/mail/e.php');}

mail($to_email, $subject_email, $mail_content, $headers);

所以我需要传递 $name 和其他变量,以便在收集时发送正确的邮件功能。

谢谢!

4

2 回答 2

0

我想出了如何做到这一点正是我正在寻找的。

我继续做 file_get_contents,但后来我在 str_replace 使用了。我把我想找到的值放在数组中,比如:

$static_content = array('$a,$b,$c');

然后使用以下命令替换:

$dynamic_content = array("$a,$b,$c");

把整个事情放在一起:

$mail_content = str_replace($static_content,$dyanmic_content,$mail_content);
于 2012-06-04T00:58:03.257 回答
0
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = isset($_POST['name']) ? htmlentities($_POST['name']) : '';
$more_info = isset($_POST['more_info']) ? htmlentities($_POST['more_info']) : '';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Hello <hello@example.com>' . "\r\n";
$to_email = 'Me <hello@me.com>';

$subject_email = 'Test Contact';

$mail_content = "Dear $name,\n\n";
$mail_content .= "$more_info";

if ($more_info == "A") { $mail_content .= file_get_contents('http://www.example.com/mail/a.php');}
if ($more_info == "B") { $mail_content .= file_get_contents('http://www.example.com/mail/b.php');}
if ($more_info == "C") { $mail_content .= file_get_contents('http://www.example.com/mail/c.php');}
if ($more_info == "D") { $mail_content .= file_get_contents('http://www.example.com/mail/d.php');}
if ($more_info == "E") { $mail_content .= include('/mail/e.php');}

mail($to_email, $subject_email, $mail_content, $headers);
于 2012-05-27T16:59:20.080 回答