doubi9999 2013-10-30 21:05
浏览 50
已采纳

PHP代码适用于Chrome,但不适用于Firefox或IE

My brother has this form:

<form id="lista" action="lista2.php" method="post">

<input name="cf_name" type="text" size="50" hidden="yes" class="obscure">
<input name="cf_email" type="text" size="50" hidden="yes" class="obscure">
<textarea name="cf_message" cols="45" rows="10" hidden="yes" class="obscure">
</textarea>
<input type="image" name="submit" value="Enviar Lista por Email" src="imagens/lista_email.png" width="40" height="40" 
onclick="this.form.elements['cf_message'].value = lista_mail;this.form.elements['cf_name'].value = prompt('Escreva o seu nome:', '');this.form.elements['cf_email'].value = prompt('Escreva o seu email:', '');">
<input name="submit2" type="submit" value="Enviar" hidden="yes" class="obscure"> 

</form>

That calls this PHP file:

<?php

if ( isset($_POST['submit']) ) {

// Dados de autenticacao SMTP
$smtpinfo['host'] = 'localhost';
$smtpinfo['port'] = '25';
$smtpinfo['auth'] = true;
$smtpinfo['username'] = 'xxx';
$smtpinfo['password'] = 'xxx';

// Dados recebidos do formulario
$nome = $_POST['cf_name'];
$email = $_POST['cf_email'];
$mensagem = $_POST['cf_message'];

// Inclusão de ficheiro PEAR. Certifique-se que o PEAR está activado no seu alojamento
require_once "Mail.php";

// Corpo da mensagem
$body = "Nome: ".$nome;
$body.= "

";
$body.= nl2br($mensagem);

$headers = array ('From' => $email,
'To' => $smtpinfo["username"],
'Subject' => 'Encomenda Website');

$mail_object = Mail::factory('smtp', $smtpinfo);

$mail = $mail_object->send($smtpinfo["username"], $headers, $body);

if ( PEAR::isError($mail) ) {
echo ("<p>" . $mail->getMessage() . "</p>");
} else {
echo ('<b><font color="FFFF00">Mensagem enviada com sucesso.<br><br></b>Seu email: ' . $email . '<br><br></font>');
}}

?>

This basically sends an email with some selected products, name and email.

The problem is that it works perfectly on Chrome, but not on FF or IE. When the submit image is pressed, the URL changes to the PHP file, but it displays a blank page.

Edit:

Added this:

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1)

FF/IE display blank page and email isn't sent, Chrome sends the email and displays this:

Strict Standards: Non-static method Mail::factory() should not be called statically in /var/www/vhosts/[site url]/httpdocs/lista2.php on line 33
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/smtp.php , dont know if it helps

The tip about the "hidden" fields, also didn't help.

  • 写回答

2条回答 默认 最新

  • dongqie7806 2013-11-02 17:42
    关注

    The issue was in: if ( isset($_POST['submit']) ) {

    because it was a image, and not a regular submit button, it was never set. (but somehow google chrome managed to put it to work)

    solution was to add to form: <input name="submit2" type="hidden" value="1"/>

    and change the PHP to: if ( isset($_POST['submit2']) ) {

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真