Jump to content

Recommended Posts

Here is your test.  Below is a simply php for sending an email to yourself and an autoreply to the person filing it out.  However, they way it's set up right now, you get the following errors

Warning: mail() [function.mail]: SMTP server response: 550 <customeremail@aol.com> No such user here in E:\inetpub\vhosts\yourdomain.com\httpdocs\test.php on line 56

Warning: Cannot modify header information - headers already sent by (output started at E:\inetpub\vhosts\yourdomain.com\httpdocs\test.php:56) in E:\inetpub\vhosts\yourdomain.com\httpdocs\test.php on line 58

 

Here is the code.  Let's see who is the best:

 

 

<?php 
$your_email 
='ME@mydomain.com';// <<=== update to your email address
$autosubject "Thank you for requesting your Free Quote";
session_start();
$errors '';
$Name '';
$Email '';

$user_message '';

if(isset(
$_POST['submit']))
{

    
    $Name $_POST['Name'];
    $Email $_POST['Email'];
    

    $user_message $_POST['message'];
    ///------------Do Validations-------------
    if(empty($Name)||empty($Email))
    {
        $errors .= "\n Name and Email are required fields. ";    
    }
    
 

// validate an email address
if( !preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i"$Email) ) {
   
$errors .= "\n You have entered and invalid email address";
}

    
if(
IsInjected($Email))
    {
        $errors .= "\n Bad email value!";
    }
    if(empty($errors))
    {
        //send the email
        //send the email
        $to $your_email;
        $subject="there is an email from a customer";
        $from $Email;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
        
        $message "This is the message from the customer";

$message2 "This is the message to the customer";
        
$headers "From: $from \r\n";
$headers .= "Reply-To: $Email \r\n";
        
$headers2 "From: Me@mydomain.com";        
$headers2 .= "Reply-To: $your-email \r\n";
        
mail($your_email,"$subject","$message","From: $Name <$Email>\n" "MIME-Version: 1.0\n" "Content-type: text/html; charset=iso-8859-1");

mail($from$autosubject$message2"From: Me <$your_email>\n" "MIME-Version: 1.0\n" "Content-type: text/html; charset=iso-8859-1");

header('Location: http://www.mydomain.com/thank-you.html');
    }
}


// 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;
  }
}

?>        
        
<!DOCUTYPE Html>
<html>
<head>
</head>

<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<?php
if(!empty($errors)){
echo 
"<p class='err'>".nl2br($errors)."</p>";
}

?>
</div>
<style type="text/css">
.blueBoxText{
    line-height:120%;
    font-size:12px;
    font-family:Arial, Verdana, Helvetica, sans-serif;
    }
</style>

<form method="POST" name="contact_form" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
<table>
            <tr><td class="blueBoxText" align="left" valign="top">
<label for='Name'>Name: </label></td></tr>
 <tr><td align="left" valign="top"><input type="text" name="Name" value='<?php echo htmlentities($Name?>' style="background-color: rgb(255, 255, 160)">
</td></tr>
 <tr><td class="blueBoxText" align="left" valign="top"><label for='Email'>Email: </label></td></tr>
 <tr><td align="left" valign="top"><input type="email" name="Email" value='<?php echo htmlentities($Email?>' style="background-color: rgb(255, 255, 160)">
</td></tr>
<tr><td align="left" valign="top"><input type="submit" value="Submit" name='submit'></td></tr></table></form>

 
</body>
</html>

@-suppress mail() and check its return value.

 

 

Oh, and

Let's see who is the best:

Trying to trick us into solving your problem by phrasing it as some sort of "contest" is insulting. There's nothing wrong with asking people for help if you don't know the answer.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.