【问题标题】:Strings failing with $_GET in php字符串在 php 中使用 $_GET 失败
【发布时间】:2014-11-26 10:24:27
【问题描述】:

我有 3 个字符串,这些字符串是从我的 php.ini 中获取的。它们实际上在脚本的早期使用成功,但是当它们使用电子邮件功能时,它会失败,如下所示:

$vagup = $_GET['vagup'];
$misto = $_GET['misto']; 
$nampao = $_GET['nampao'];

$staement = $dbh->prepare('SELECT earlybird FROM databaser WHERE mastppp = :fasto AND feats = :gamerop');
    $staement->execute( array( 'fasto' => $misto, 'gamerop' => $nampao ) );
    $results = $staement->fetch(PDO::FETCH_ASSOC);
$masto = $results['earlybird'];
$to      = $masto;
$subject = 'Paid $'. $vagup . ' from the script';
$message = 'This is a receipt for your payment of $'. $vagup . ' from the script';
$headers = 'From: theemail@gmail.com' . "\r\n" .
    'Reply-To: theemail@gmail.com'  . "\r\n".
    'X-Mailer: PHP/' . phpversion(); 
mail($to, $subject, $message, $headers);
$staement = $dbh->prepare('SELECT stain FROM databaser WHERE mastppp = :fasto AND feats = :gamerop');   
    $staement->execute( array( 'fasto' => $misto, 'gamerop' => $nampao ) );
    $results = $staement->fetch(PDO::FETCH_ASSOC);
$masto = $results['stain'];  
$to      = $masto;
$subject = $nampao .' paid $'. $vagup . ' from the script';
$message = 'This is a receipt for the payment of $'. $vagup . ' from the script by '. $nampao;
$headers = 'From: theemail@gmail.com' . "\r\n" .
    'Reply-To: theemail@gmail.com'  . "\r\n".
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

奇怪的是,当我插入虚拟字符串时,它就可以工作了。

$vagup = "rambo";
$misto = "mistoblue"; 
$nampao = "heyu";

【问题讨论】:

  • 编码后传递邮件。
  • 这些变量真的和你认为的一样吗?尝试回显它们或错误记录它们以确保。
  • 确实如此。刚做了。这几乎就像他们与邮寄或其他东西发生冲突。
  • 当您在查询字符串中传递电子邮件时对其进行编码。
  • 我该怎么做?

标签: php string get


【解决方案1】:

试试这个

 $vagup = filter_input(INPUT_GET, 'vagup', FILTER_DEFAULT);
    $misto = filter_input(INPUT_GET, 'misto', FILTER_DEFAULT);
    $nampao = filter_input(INPUT_GET, 'nampao', FILTER_DEFAULT);

【讨论】:

    【解决方案2】:

    你可以使用

    string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding = mb_internal_encoding() ] )

    将字符串str的字符编码从可选的from_encoding转换为to_encoding

    如果没有指定from_encoding,将使用内部编码。

    • 在此重试传递电子邮件后

    You can find documentation with examples over here!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多