我一直在试图弄清楚如何完成这个PHP脚本,我认为它真的会帮助我和其他人试图创建一个保存QR码的脚本,然后允许将它们发送给那些创造了他们。我目前要做的是创建一个QR码生成器,通过电子邮件向个人发送从名称和电子邮件信息信息动态生成的QR码。基本上,这里的目标是在URL中执行PHP Get Request以在站点上显示用户的动态PHP页面。
如果这没有意义,请告诉我,我真的很感激任何和所有的帮助,并且觉得这是一个其他人可能需要帮助的问题!
<?php
if ( isset( $_POST['submit'] ) ) {
$hostname = 'localhost';
$user = 'username';
$pass = 'password';
$dbase = 'database';
$connection = mysql_connect( "$hostname" , "$user" , "$pass" )
or die ( "Can't connect to MySQL" );
$db = mysql_select_db( $dbase , $connection ) or die ( "Can't select database." );
function clean( $var )
{
$dirtystuff = array( "\\", "/", "*", "'", "=", "#", ";", "<", ">", "+", "%" );
return mysql_real_escape_string( str_replace( $dirtystuff , "" , $var ) ) ;
}
$_POST = array_map( "clean", $_POST );
$name = $_POST['name'];
$email = $_POST['email'];
$sql = "INSERT INTO qrdb (Name, Email)
VALUES ('$name', '$email');";
mysql_query( $sql ) or die( "Couldn't run the query: " . $sql . " - " . mysql_error()
);
mysql_close();
}
$filename = "$HELPWITHVAR";
$width = 400;
$height = 400;
if (!file_exists($filename))
{
$url = urlencode("DynamicURLHEREWithNameAndEmailInfoInAGetRequestFormat");
$qr = file_get_contents("http://chart.googleapis.com/chart?chs=
{$width}x{$height}&cht=qr&chl=$url");
file_put_contents($filename, $qr);
}
echo "<img src=\"$filename\" width=\"$width\" height=\"$height\" alt=\"Scan my QR !\"
/>";
$to = "$_POST['email']";
$subject = "QR Code for you!";
$message = "
<html>
<body>
<p>Here is your QR Code!</p>
<p><?php echo $filename ?></p>
</body>
</html>";
$headers .= 'From: <email@domain.com>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
答案 0 :(得分:0)
你不能把PHP标签放在电子邮件中 - 它们不会被执行!
您需要直接调用图像
<p>Here is your QR Code!</p>
<p><img src="http://chart.googleapis.com/chart?chs=
400x400&cht=qr&chl=http://example.com/"
width="400" height="400" alt="Scan my QR !" />"
</p>
将example.com替换为任何URL。