Php Sending mail help

Status
Not open for further replies.
5 comments
Update your html code to this:
PHP:
<!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>
    
    <div class="heading">
        <div class="shell">
            <table width="990" height="458" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="72%" height="458" align="left" valign="top"><table width="99%" height="433" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="6%" height="433" align="left" valign="top"><p align="justify" class="content">&nbsp;</p>          </td>
        <td width="94%" align="left" valign="top"><span class="style63">Contact</span><br />
            <br />
            <span class="content">Feel free to contact us by using our address and telephone information on the right hand panel, 
or to email us, please fill in the form below.</span><br />
            <br />
            <form name="contactform" method="post" action="contact.php">
            <table width="653" height="332" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                                   <form id="" name="" method="" action="contact.php">
                <td width="653" height="332" align="left" valign="top" background="sas/home_files/spacer.gif" scope="col">
                
                  <table width="104%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tbody>
                      <tr>
                        <td width="143" align="left" valign="middle" class="style26"><strong>Name </strong>*</td>
                        <td width="289" align="left" valign="middle"><span id="sprytextfield2">
                          <input name="Name" id="name" class="form" type="text" />
                          </td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" class="style75"><font class="style26"><strong>Title</strong></font></td>
                        <td align="left" valign="middle"><input name="Title" id="title" class="form" type="text" />                        </td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" class="style75"><font class="style26"><strong>Company</strong></font></td>
                        <td align="left" valign="middle"><input name="Company" id="company" class="form" type="text" />                        </td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" class="style26"><strong>Email </strong>*</td>
                        <td align="left" valign="middle"><span id="sprytextfield1">
                          <input name="Email" id="email" class="form" type="text" />
                          </td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" class="style26"><span class="textbold style18 style71 style87"><font class="style26"><strong>Phone</strong></font></span><span class="style87"> <span class="style85"><font class="style26">*</font></span></span></td>
                        <td align="left" valign="middle"><span id="sprytextfield3">
                          <input name="Phone" id="mnumber" class="form" type="text" />
                          </td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" class="style86"><img src="contact.php_files/clear_dot.htm" alt="" width="1" border="0" height="5" /><br />
                            <strong class="style26">Address</strong></td>
                        <td align="left" valign="middle"><textarea name="Address" id="address" class="form"></textarea>                        </td>
                      </tr>
                      
                      <tr>
                        <td valign="top" class="style76"><font face="Verdana, Arial, Helvetica, sans-serif" class="textbold style18 style87"> <strong>Details</strong></font></td>
                        <td align="left" valign="middle" class="style77" id="form_fix"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
                          <textarea name="Details" cols="31" rows="5" class="form" id="Details"></textarea>
                        </font></font></td>
                      </tr>
                      <tr>
                        <td height="24" align="left" valign="middle">&nbsp;</td>
                        <td valign="middle" id="form_fix"><label>
                          <input type="submit" name="Submit" value="Submit" />
                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                          <input type="reset" name="Submit2" value="Reset" />
                        </label></td>
                      </tr>
                      <tr>
                        <td height="19" colspan="2" align="left" valign="middle">&nbsp;</td>
                      </tr>
                    </tbody>
                  </table>
                </form>
                </td>
              </tr>
            </table>
          </td>
      </tr>
    </table>
      <br />
    </td>
    <td width="28%" align="center" valign="top"><br />
      <table width="273" height="127" border="0" cellpadding="0" cellspacing="0" class="contactbox">
        <tr>
          <td height="125"><div id="pad">
              <div>
                <div class="graphic"><div class="top"><div class="bottom">
                    
                </div></div></div>
                
          </div></td>
        </tr>
      </table></td>
  </tr>
</table>
</div>
<div id="footer">
    <div class="shell">
        <ul>
           
            
    <div class="cl">&nbsp;</div>
</div>
<div class="cl">&nbsp;</div>
</body>
</html>

And your php code to:
PHP:
<?php
if(isset($_POST['Email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "emailo@site.com";
$email_subject = "Contact Us";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Name']) ||
!isset($_POST['Title']) ||
!isset($_POST['Company']) ||
!isset($_POST['Email']) ||
!isset($_POST['Phone']) ||
!isset($_POST['Address']) ||
!isset($_POST['Details'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$Name = $_POST['Name']; // required
$Title = $_POST['Title']; // not required
$Company = $_POST['Company']; // not required
$$email_from = $_POST['Email']; // required
$Phone = $_POST['Phone']; // required
$Address = $_POST['Address']; // not required
$Details = $_POST['Details']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Name)) {
$error_message .= 'Name you entered does not appear to be valid.<br />';
}
$string_exp = "/^[0-9.-]+$/";
if(!preg_match($string_exp,$Phone)) {
$error_message .= 'Phone Number you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($Name)."\n";
$email_message .= "Title: ".clean_string($Titlee)."\n";
$email_message .= "Company: ".clean_string($Company)."\n";
$email_message .= "Email: ".clean_string($Email)."\n";
$email_message .= "Phone: ".clean_string($Phone)."\n";
$email_message .= "Address: ".clean_string($Addresse)."\n";
$email_message .= "Details: ".clean_string($Details)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>

The errors were:
- You were using lowercase letters to send form data, however in php file you are checking for CamelCase
- In php file, it checks for both of email and Email and only 1 of them is set offcourse
 
Thank you updated code as mentioned above and getting same error

We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
The Email Address you entered does not appear to be valid.
Please go back and fix these errors.
 
In the php code you have this
$$email_from = $_POST['Email']; // required
$email_message .= "Title: ".clean_string($Titlee)."\n";
$email_message .= "Company: ".clean_string($Company)."\n";
$email_message .= "Email: ".clean_string($Email)."\n";
$email_message .= "Phone: ".clean_string($Phone)."\n";
$email_message .= "Address: ".clean_string($Addresse)."\n";
should be this
$email_from = $_POST['Email']; // required
$email_message .= "Title: ".clean_string($Title)."\n";
$email_message .= "Company: ".clean_string($Company)."\n";
$Email = $_POST['Email']; // required;
$email_message .= "Email: ".clean_string($Email)."\n";
$email_message .= "Phone: ".clean_string($Phone)."\n";
$email_message .= "Address: ".clean_string($Address)."\n";
 
Last edited:
Status
Not open for further replies.
Back
Top