Email 用动态值传递给邮件特定文档的PHP值

Email 用动态值传递给邮件特定文档的PHP值,email,include,file-get-contents,php,Email,Include,File Get Contents,Php,我期待着发送一个动态电子邮件的基础上,他们在网站的形式使用什么选择。目前我有: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $name = isset($_POST['name']) ? htmlentities($_POST['name']) : ''; $more_info = isset($_POST['more_info']) ? htmlentities($_POST['more_info']) : ''; $headers

我期待着发送一个动态电子邮件的基础上,他们在网站的形式使用什么选择。目前我有:

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);
if($\u服务器['REQUEST\u METHOD']=='POST'){
$name=isset($_POST['name'])?htmlentities($_POST['name']):“”;
$more\u info=isset($\u POST['more\u info'])?htmlentities($\u POST['more\u info']):“”;
$headers='MIME版本:1.0'。“\r\n”;
$headers.=“内容类型:text/html;字符集=iso-8859-1”。“\r\n”;
$headers.='发件人:你好'。“\r\n”;
$to_email='Me';
$subject_email='测试联系人';
如果($more\u info==“A”){$mail\u content=file\u get\u contents('http://www.example.com/mail/a.php');}
如果($more\u info==“B”){$mail\u content=file\u get\u contents('http://www.example.com/mail/b.php');}
如果($more\u info==“C”){$mail\u content=file\u get\u contents('http://www.example.com/mail/c.php');}
如果($more\u info==“D”){$mail\u content=file\u get\u contents('http://www.example.com/mail/d.php');}
如果($more_info==“E”){$mail_content=include('/mail/E.php');}
邮件($to_email、$subject_email、$mail_content、$headers);
因此,我需要传递$name和其他变量,以便在收集邮件时发送正确的邮件函数

谢谢!

if($\u服务器['REQUEST\u METHOD']=='POST'){
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);
$name=isset($_POST['name'])?htmlentities($_POST['name']):“”; $more\u info=isset($\u POST['more\u info'])?htmlentities($\u POST['more\u info']):“”; $headers='MIME版本:1.0'。“\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1”。“\r\n”; $headers.='发件人:你好'。“\r\n”; $to_email='Me'; $subject_email='测试联系人'; $mail\u content=“亲爱的$name,\n\n”; $mail\u content.=“$more\u info”; 如果($more\u info==“A”){$mail\u content.=file\u get\u contents('http://www.example.com/mail/a.php');} 如果($more\u info==“B”){$mail\u content.=文件\u get\u contents('http://www.example.com/mail/b.php');} 如果($more\u info==“C”){$mail\u content.=file\u get\u contents('http://www.example.com/mail/c.php');} 如果($more\u info==“D”){$mail\u content.=文件\u get\u contents('http://www.example.com/mail/d.php');} 如果($more_info==“E”){$mail_content.=include('/mail/E.php');} 邮件($to_email、$subject_email、$mail_content、$headers);
我找到了我想要的方法

我继续执行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);

谢谢@Rodney,但我想在side example.com/mail/a.PHP中将值传递给PHP值。我上次可能没有说清楚。这可能吗?Thanks@Dan在上面的示例中,定义的变量$name和$more_info将可用于example.com/mail/a.php,因为您将其包含在脚本中_无论您希望它出现在example.com/mail/a.php中的什么位置,它都会显示出来。