Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

HEELLP!!!!! I can't get mail() to work!!

the mail() function

Moderators: macek, egami, gesf

HEELLP!!!!! I can't get mail() to work!!

Postby danmattos » Tue Sep 10, 2013 6:13 am

Hey guys!!

I'm really new at this so please bare with me!! I've been trying to get the following code to send, but for some reason it doesn't work online. If I preview the file locally, the javascript saying that the email was successful appears. I was just wondering if anyone could check my code... I tried talking to the web-hosting admin and he said it was a coding issue but I have no clue what I'm doing.

Also, I tried to do a data validation but I got lost with the if's, I just want to check that there is valid email address, that the other fields are filled and that the comments field is long enough that it would actually be useful. And to top it of with a cherry, I would like this to be a javascript alert. Disclaimer: I have actually tried a zillion codes that didn't work and I deleted them all to start from scratch but I f I don't know the actual language I can't get very far.

Here is the script (sorry guys if it's in spanish, I haven't gotten around to translating the page):

Code: Select all
<?php
$field_nombre = $_POST["nombre"];
$field_apellido = $_POST["apellido"];
$field_email = $_POST["email"];
$field_tipo = $_POST["tipo"];
$field_comments = $_POST["comments"];

/* No sé cómo hacer que haga un VALIDATE de los campos del formulario y que cuando clickee Enviar le aparezca un java alert indicandole que revise la info inputeada. No sé si se puede hacer o no. */

$to = 'contacto@s-led.cl';
$subject = "Contacto Web ".$field_tipo .$field_nombre .$field_apellido;

$body_message = "Tipo: ".$field_tipo."\n";
$body_message .= "From: ".$field_name .$field_apellido."\n";
$body_message .= "E-mail: ".$field_email."\n";
$body_message .= "Message: ".$field_message;

$headers = "From: ".$field_email."\r\n";
$headers .= "Reply-To: ".$field_tipo."\r\n";
$headers .= "Reply-To: ".$field_email."\r\n";

$email_status = mail($to,$subject,$headers,$body_message);

if ($email_status) { ?>
   <script language="javascript" type="text/javascript">
      alert("Gracias por contactarnos. Un representante se contactara con usted a la brevedad");
      window.location = "Contact.html";
   </script>
<?php
}
else { ?>
   <script language="javascript" type="text/javascript">
      alert("Error en el mensaje. Por favor reintente o comuniquese con contacto@s-led.cl");
      window.location = "Contact.html";
   </script>
<?php
}
?>


And here is the form:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Contacto</title>
<style type="text/css">
<!--
body {
   margin_top: 40px
   margin-left: 30px;
   position: relative;
   height: auto;
   width: 700px;
   font-family: "Eras Light ITC", "Eras Medium ITC", "Eras Bold ITC", "Eras Demi ITC";
   font-size: 18px;
   left: 40px;
   top: 30px;
}
.Style1 {font-size: 18px; font-weight: bold; color: #63B040;}
a:link {
   color: #63B040;
}
a:visited {
   color: #63B040;
}
a:hover {
   color: #63B040;
}
a:active {
   color: #63B040;
   font-weight: bold;
}
-->
</style></head>

<body>
<form action="enviarformulario.php" method="post" enctype="multipart/form-data" name="fromContacto" target="_self" id="fromContacto">
<p align="Left" style="font-size: 24px; color: #68BD45; font-weight: bold;"><img src="img/GreenArrow.jpg"/> Contacto</p>
<p>
Para unirte a la revolución LED basta con que nos envíes un correo y podremos empezar a diseñar una solución especial para tí y tus necesidades.</p>
<table width="665">
<tr>
 <td valign="top">
  <label for="nombre">Nombre *</label>
 </td>
 <td valign="top">
  <input  type="text" name="nombre" maxlength="50" size="15" />
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="apellido">Apellido *</label>
 </td>
 <td valign="top">
  <input  type="text" name="apellido" maxlength="50" size="15" />
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="email">Email *</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="80" size="30" />
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="tipo">Tipo *</label>
 </td>
 <td valign="top"><select name="tipo" title="Tipo" dir="ltr">
   <option selected="selected">Elige una opción...</option>
   <option value="Cliente">Cliente</option>
   <option value="Proveedor">Proveedor</option>
   <option value="Otro">Otro</option>
 </select></td>
</tr>
<tr>
 <td valign="top">
  <label for="comments">Mensaje *</label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="50" rows="10"></textarea>
 </td>
</tr>
<tr>
 <td colspan="2" style="text-align:center">
     <input name="submitted" type="submit" id="submitted" value="Enviar" action="$_POST"/>
 </td>
 </tr>
 <tr>
<td height="53" colspan="2" align="center" style="font-size: 16px; color: #68BD45; font-weight: lighter;">Cualquier información entregada en esta página será tratada con la máxima confidencialidad.</td>
</tr>
</table>
</form>
</body>

</html>
danmattos
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Sep 04, 2013 11:33 pm

Re: HEELLP!!!!! I can't get mail() to work!!

Postby johnj » Thu Sep 12, 2013 12:39 am

right after $email_status = mail(), add the following:
$error = error_get_last();
Now print this $error and see what is going wrong.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: HEELLP!!!!! I can't get mail() to work!!

Postby danmattos » Thu Sep 12, 2013 5:09 am

Ok. where should i put the print? After the if's? can I tell it to print in a different page just so that i don't get things confused (how can i do this?)?

Thanks a lot.

johnj wrote:right after $email_status = mail(), add the following:
$error = error_get_last();
Now print this $error and see what is going wrong.
danmattos
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Sep 04, 2013 11:33 pm

Re: HEELLP!!!!! I can't get mail() to work!!

Postby johnj » Sun Sep 15, 2013 5:52 am

above the "if", right after this line, $error = error_get_last();
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.