问题描述
我的兄弟有这样的形式:
<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>
调用此PHP文件:
<?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.= "\n\n";
$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.
问题是它在Chrome上完美工作,但不能在FF或IE上运行。当提交图像被按下时,URL将更改为PHP文件,但显示空白页。
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.
编辑: / strong>
已添加:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1)
FF / IE显示空白页和电子邮件不发送,Chrome发送电子邮件并显示:
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.
推荐答案
问题出在: if(isset($ _ POST ['submit'])){
因为它是一个图像,而不是一个常规的提交按钮从未设定(但不知何故,谷歌chrome设法使其工作)
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)
解决方案是添加到形式:< input name =submit2type = hiddenvalue =1/>
solution was to add to form: <input name="submit2" type="hidden" value="1"/>
并将PHP更改为: if(isset _POST ['submit2'])){
这篇关于PHP代码适用于Chrome,但不适用于Firefox或IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!