• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

Simple Mailto Form

I am unable to make my contact us email form work. Here is my code:
Send_mail.php:
 
<?php

$webmaster_email = "josemejiav@hotmail.com";
$feedback_page = "contactenos.php";
$error_page = "contactenos_error.php";
$thankyou_page = "contactenos_gracias.html";
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['phone'] ;
$subject = $_REQUEST['subject'] ;
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;
	}
}
if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}
elseif (empty($email_address) || empty($comments)) {
header( "Location: $error_page" );
}
elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}
else {
mail( "$webmaster_email", "Feedback Form Results",
  $comments, "From: $email_address", $name);
header( "Location: $thankyou_page" );
}
?>

Open in new window

contactenos.php - Form Portion
 
<td width="100%" height="100%" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tbody>
          <tr>
            <td width="100%" height="63" align="left" valign="top" style="background-repeat:no-repeat; background-position:right top; padding-top:20px; padding-left:10px;"><font class="asd" size="+2"><strong><font face="Tahoma, Geneva, sans-serif">Si desea cotizar una obra a pedido, o desea comprar al por mayor, consulte sin&nbsp; compromiso. En breve le responderemos. Gracias.</font></strong></font>
<br/>
<br/>
<font class="asd"><strong><font face="Tahoma, Geneva, sans-serif">Su informaci&oacute;n de contacto:</font></strong></font><br/>
<HR color=#5b5b5b>
<form action="send_mail.php" method="post">
<table>
<tr>
<td><font class="asd"><strong><font face="Tahoma, Geneva, sans-serif" size="-1">Direcci&oacute;n E-mail:</font></strong></font><br/></td>
<td>
<input type="text" name="email_address" value="" maxlength="100" />
</td>
</tr>
<tr>
<td><font class="asd"><strong><font face="Tahoma, Geneva, sans-serif" size="-1">Nombre Completo:</font></strong></font><br/></td>
<td>
<input type="text" name="name" value="" maxlength="100" />
</td>
</tr>
<tr>
<td><font class="asd"><strong><font face="Tahoma, Geneva, sans-serif" size="-1">Tel&eacute;fono:</font></strong></font><br/></td>
<td>
<input type="text" name="phone" value="" maxlength="100" />
</td>
</tr>
</table>
<HR color=#5b5b5b>
<table>
<tr>
<td><font class="asd"><strong><font face="Tahoma, Geneva, sans-serif" size="-1">Tema:</font></strong></font><br/></td>
<td>
<input type="text" name="subject" value="" maxlength="100" />
</td>
</tr>
<tr>
<td valign="top"><font class="asd"><strong><font face="Tahoma, Geneva, sans-serif" size="-1">Consulta:</font></strong></font><br/></td>
<td>
<textarea rows="10" cols="50" name="comments"></textarea>
</td>
</tr>
<tr><td>&nbsp;</td>
<td>
<input type="submit" value="Mandar" />
</td>
</tr>
</table>
</form>
</td>
          </tr>
</tr>
</tbody>
</table>
</td>

Open in new window

contactenos_error.php - Error message
 
<td width="100%" height="100%" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tbody>
          <tr>
            <td width="100%" height="63" align="left" valign="top" style="background-repeat:no-repeat; background-position:right top; padding-top:20px; padding-left:10px;"><font class="asd" size="+2"><strong><font face="Tahoma, Geneva, sans-serif">Error!<br/>Por favor, asegúrese de haber completado los campos antes de enviar el formulario.<br/>
<br/>Asegúrese también de que sólo hay una dirección de correo electrónico.</font></strong></font> <br/><br/><br/>
<tr>
    <td width="100%" height="100%" align="center" valign="top" bgcolor="#FFFFFF"><font class="asd" size="+2"><strong><font face="Tahoma, Geneva, sans-serif"><a href="/arteperubol/admin/contactenos.php"><u>Volver al Formulario</u></a></font></strong></font></td>
  </tr>
<br/>
<br/>

          </tr>
</tr>
</tbody>
</table>
</td>

Open in new window

contactenos_gracias.php - Thankyou message
<td width="100%" height="100%" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tbody>
          <tr>
            <td width="100%" height="63" align="left" valign="top" style="background-repeat:no-repeat; background-position:right top; padding-top:20px; padding-left:10px;"><font class="asd" size="+2"><strong><font face="Tahoma, Geneva, sans-serif">Gracias!<br/>Su consulta fue enviada correctamente</font></strong></font> <br/><br/><br/>
<tr>
    <td width="100%" height="100%" align="center" valign="top" bgcolor="#FFFFFF"><font class="asd" size="+2"><strong><font face="Tahoma, Geneva, sans-serif"><a href="/arteperubol/admin/contactenos.php"><u>Volver al Formulario</u></a></font></strong></font></td>
  </tr>
<br/>
<br/>

          </tr>
</tr>
</tbody>
</table>
</td>

Open in new window

Does anyone have any suggestions as to what I'm doing wrong?
Thanks in advance
0
whocaresaboutit
Asked:
whocaresaboutit
1 Solution
 
Christopher Raymond MendozaCommented:
What does the logs say?
0
 
whocaresaboutitAuthor Commented:
I'm getting
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\AppServ\www\arteperubol\admin\send_mail.php on line 67

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\arteperubol\admin\send_mail.php:67) in C:\AppServ\www\arteperubol\admin\send_mail.php on line 68
0
 
Ray PaseurCommented:
Something is very strange here.  The Warning messages identify lines 67- 68, but there is no line 67 or 68 in any of the code posted here.  Are you sure you are running the correct scripts?

The code snippet shows the general design pattern for a form-to-email.  You might try running this version to see what you get.
<?php // RAY_form_to_email.php
error_reporting(E_ALL);


// SEND MAIL FROM A FORM


// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "NoReply@Your.org";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS - CHANGE THESE FOR YOUR WORK
$to[]  = "You@Your.org";
$to[]  = "Her@Your.org";
$to[]  = "Him@Your.org";



// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE THROUGH STRING CONCATENATION
    $content    = NULL;
    $content   .= "You have a New Query From $name" . PHP_EOL . PHP_EOL;
    $content   .= "Tel No: $telephone" . PHP_EOL;
    $content   .= "Email: $email" . PHP_EOL;

    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "MAIL WORKED FOR $recipient";
        }
    }
}


// A FORM TO TAKE CLIENT INPUT FOR THIS SCRIPT
$form = <<<ENDFORM
<form method="post">
Please enter your contact information
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>
ENDFORM;

echo $form;



// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    // IF MAGIC QUOTES IS ON, WE NEED TO REMOVE SLASHES
    $str = stripslashes($str);

    // REMOVE EXCESS WHITESPACE
    $rgx
    = '/'               // REGEX DELIMITER
    . '\s'              // MATCH THE WHITESPACE CHARACTER(S)
    . '\s+'             // MORE THAN ONE CONTIGUOUS INSTANCE OF WHITESPACE
    . '/'               // REGEX DELIMITER
    ;
    $str = preg_replace($rgx, ' ', $str);

    // REMOVE UNWANTED CHARACTERS
    $rgx
    = '/'               // REGEX DELIMITER
    . '['               // START OF A CHARACTER CLASS
    . '^'               // NEGATION - MATCH NONE OF THE CHARACTERS IN THIS CLASS
    . 'A-Z0-9&+:?_.- '  // CHARACTERS WE WANT TO KEEP
    . ']'               // END OF THE CHARACTER CLASS
    . '/'               // REGEX DELIMITER
    . 'i'               // CASE-INSENSITIVE
    ;
    $str = preg_replace($rgx, NULL, $str);

    return $str;
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now