获得此HTML联系表单:
<form action="contact.php" method="get">
Nombre<br>
<input type="text" name="cf_name"><br>
Email<br>
<input type="text" name="cf_email"><br>
Mensaje<br>
<textarea name="cf_message"> </textarea><br>
<input type="submit" value="Enviar">
</form>
另外一个发送联系信息的php文件:
$mail_to = 'tienda@shambricolage.com';
$subject = 'Mensaje de Contacto de Sham Bricolage - '.$field_name;
$body_message = 'Persona de contacto: '.$field_name."\n";
$body_message .= 'E-mail de contacto: '.$field_email."\n";
$body_message .= 'Mensaje: '.$field_message;
$headers = 'De: '.$field_email."\r\n";
$headers .= 'Responder a: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Gracias por su mensaje');
window.location = 'contacto.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('No se pudo enviar. Por favor, contacte por email a tienda@shambricolage.com');
window.location = 'contacto.html';
</script>
<?php
}
?>
在表单提交时,页面无法加载,Web会一直加载而根本没有发送电子邮件。您可以在提交表单时在http://www.shambricolage.com/Contacto.html上查看此内容,无需加载任何内容。
完成名为网页制作工具的工具
答案 0 :(得分:0)
我改变了一下。不知道它是否有效。但它搞砸了并没有很好地编程。
HTML:
<form action="contact.php" method="GET">
Nombre<br>
<input type="text" name="cf_name"><br>
Email<br>
<input type="text" name="cf_email"><br>
Mensaje<br>
<textarea name="cf_message"> </textarea><br>
<input type="submit" value="Enviar">
</form>
PHP:
ob_start();
$field_name = $_GET['cf_name'];
$field_email = $_GET['cf_email'];
$field_message = $_GET['cf_message'];
$mail_to = 'tienda@shambricolage.com';
$subject = 'Mensaje de Contacto de Sham Bricolage - '.$field_name;
$body_message = 'Persona de contacto: '.$field_name."\n";
$body_message .= 'E-mail de contacto: '.$field_email."\n";
$body_message .= 'Mensaje: '.$field_message;
$headers = 'De: '.$field_email."\r\n";
$headers .= 'Responder a: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Gracias por su mensaje');
</script>
<?php
header('Location: contacto.html');
}
else { ?>
<script language="javascript" type="text/javascript">
alert('No se pudo enviar. Por favor, contacte por email a tienda@shambricolage.com');
</script>
<?php
header('Location: contacto.html');
}
?>
答案 1 :(得分:0)
最后,在联系托管团队之后,它是一个STMP服务器,我必须填写一个包含附加信息的完整PHP邮件文件,如此处所示。
<?php
error_reporting( E_ALL & ~( E_NOTICE | E_STRICT | E_DEPRECATED ) ); //Aquí se genera un control de errores "NO BORRAR NI SUSTITUIR"
require_once "Mail.php"; //Aquí se llama a la función mail "NO BORRAR NI SUSTITUIR"
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$to = 'tienda@shambricolage.com'; //Aquí definimos quien recibirá el formulario
$from = 'tienda@shambricolage.com'; //Aquí definimos que cuenta mandará el correo, generalmente perteneciente al mismo dominio
$host = '217.116.0.228'; //Aquí definimos cual es el servidor de correo saliente desde el que se enviaran los correos
$username = 'tienda.shambricolage.com'; //Aqui se define el usuario de la cuenta de correo
$password = '****'; //Aquí se define la contraseña de la cuenta de correo que enviará el mensaje
$subject = 'Mensaje de la tienda Shambricolage'; //Aquí se define el asunto del correo
$body = 'Persona de contacto: '.$field_name."\n";
$body .= 'E-mail de contacto: '.$field_email."\n";
$body .= 'Mensaje: '.$field_message;
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
?>
<script language="javascript" type="text/javascript">
alert('No se pudo enviar el mensaje. Por favor, escriba a tienda@shambricolage.com');
window.location = 'index.html';
</script>
<?php
} else {
?>
<script language="javascript" type="text/javascript">
alert('Gracias por su mensaje');
window.location = 'index.html';
</script>
<?php
}
?>