我有一个我正在工作的网站的基本联系表格。我使用HTML和PHP来做到这一点。
该 HTML:
<form action="enviarc.php" method="post" name="contacto" target="pop" id="cntct-c" onsubmit="pop = window.open('about:blank','pop', 'width=400,height=250');this.submit(); this.reset(); return false;">
<p>
<input name="nombre" type="text" id="campos-n" class="form-imputs" size= "36" placeholder="Nombre *"/>
</p>
<p>
<input name="email" type="text" id="campos-em" class="form-imputs" size="36" placeholder="Email *"/>
</p>
<p>
<input name="telefono" type="text" id="campos-te" class="form-imputs" size="36" placeholder="Teléfono"/>
</p>
<p>
<input name="celular" type="text" id="campos-ce" class="form-imputs" size="36" placeholder="Celular"/>
</p>
<p>
<input name="ciudad" type="text" id="campos-ci" class="form-imputs" size="36" placeholder="Ciudad"/>
</p>
<p>
<textarea name="mensaje" id="campos-m" class="form-imputs" cols="36" rows="6" placeholder="Mensaje *" style="height:100px;"></textarea>
</p>
<input name="Submit" type="submit" class="form-buttons" value="Enviar"/>
<input name="Clean" type="reset" class="form-buttons" value="Limpiar">
</form>
和PHP:
<?php
if(isset($_POST['email'])) {
$email_to = "xxx@xxx";
$email_subject = "Contacto desde el formulario de xxxxxx";
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$celular = $_POST['celular'];
$ciudad = $_POST['ciudad'];
$mensaje = $_POST['mensaje'];
$email_message .= "Nombre: ".($nombre)."'n";
$email_message .= "Email: ".($email)."'n";
$email_message .= "Telefono: ".($telefono)."'n";
$email_message .= "Celular: ".($celular)."'n";
$email_message .= "Ciudad: ".($ciudad)."'n";
$email_message .= " 'n";
$email_message .= "Mensaje: ".($mensaje)."'n";
//$email_message .= "Enviado el " . date('d-m-Y', time());
// create email headers
$headers = 'From: '.$email."'r'n".
'Reply-To: '.$email."'r'n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('('n+)',
'('r+)',
'('t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!-- include your own success html here -->
Su mensaje fue enviado correctamente.<br>XXXXXXXX estara en contacto con usted.
<?php
}
?>
我不是php开发人员,我是网页设计师,所以我使用教程中的一些代码。问题是代码在 Firefox 中运行良好,发送电子邮件并且工作正常,但在 Google Chrome 中表单中断并且不发送电子邮件。单击"提交"按钮时,弹出窗口将打开并显示"消息已发送"文本,但电子邮件不会发送。
我已经在网上搜索过,我读到谷歌浏览器和PHP"$_POST"和"提交"之间的问题,但我无法解决这些问题。
欢迎任何建议或指向在大多数浏览器中有效的功能php表单教程的链接(尽管我阅读了很多,但找不到有效的),是为了工作,时间已经结束了,我:)像每次一样...
我回答我自己的问题。也许答案对其他人有用。
问题来自打开"文件.php"的目标。我在标签中使用 JavaScript 行在弹出窗口中打开"评论已发送"消息。谷歌浏览器对此有问题,所以我解决了自我页面上的"感谢页面"的问题。