Pls Help Me !

Discussion in 'PHP' started by seoindia, Aug 26, 2006.

  1. #1
    I have been using following enquiry form in php for all of my websites. Suddenly our hosting provider in order to prevent Spam stopped mail forwarding and as a result i am not getting mails at another email id other than domain name. He suggested me to send mails in forms by an email account instaed of nobody option. I donnt know how to do that it will be a great help if somebody can edit the following form and tell me how to do it. Thanks in advance.

    <?
    $recipient ="mohitpuri@gmail.com";
    $from = $_POST['email'];
    $referers = array ('abc.com','www.abc.com');
    $version = "4.0";
    function print_error($reason,$type = 0) {
    global $version;
    build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
    if ($type == "missing") {
    ?>
    The form was not submitted for the following reasons:<p>
    <title></title><ul><?
    echo $reason."\n";
    ?></ul>
    Try again.<?
    } else {
    ?>
    The form was not submitted because :<p>
    <?
    }
    echo "<br><br>\n";
    echo "<small>Powered by Technosoft Services/a></small>\n\n";
    exit;
    }
    function check_referer($referers){
    if (count($referers)){
    $found = false;
    $temp = explode("/",getenv("HTTP_REFERER"));
    $referer = $temp[2];
    for ($x=0; $x < count($referers); $x++){
    if (ereg ($referers[$x], $referer)) {
    $found = true;
    }
    }
    if (!$found){
    print_error("You are coming from an <b>unauthorized domain.</b>");
    error_log("[form.php] Illegal Referer. (".getenv("HTTP_REFERER").")", 0);
    }
    return $found;
    } else {
    return true;
    }
    }
    if ($referers)
    check_referer($referers);

    function parse_form($array) {
    $reserved_keys[] = "MAX_FILE_SIZE";
    $reserved_keys[] = "required";
    $reserved_keys[] = "redirect";
    $reserved_keys[] = "email";
    $reserved_keys[] = "require";
    $reserved_keys[] = "path_to_file";
    $reserved_keys[] = "recipient";
    $reserved_keys[] = "subject";
    $reserved_keys[] = "bgcolor";
    $reserved_keys[] = "text_color";
    $reserved_keys[] = "link_color";
    $reserved_keys[] = "vlink_color";
    $reserved_keys[] = "alink_color";
    $reserved_keys[] = "title";
    $reserved_keys[] = "missing_fields_redirect";
    $reserved_keys[] = "env_report";
    if (count($array)) {
    while (list($key, $val) = each($array)) {
    $reserved_violation = 0;
    for ($ri=0; $ri<count($reserved_keys); $ri++) {
    if ($key == $reserved_keys[$ri]) {
    $reserved_violation = 1;
    }
    }
    // prepare content
    if ($reserved_violation != 1) {
    if (is_array($val)) {
    for ($z=0;$zcount($val);$z++) {
    $content .= "$key: $val[$z]\n";
    }
    } else {
    $content .= "$key: $val\n";
    }
    }
    }
    }
    return $content;
    }

    // mail the content we figure out in the following steps

    function mail_it($content, $subject, $from, $recipient) {
    mail($recipient, $subject, $content, "-f ");
    }

    // take in the body building arguments and build the body tag for page display
    function build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet) {
    if ($style_sheet)
    echo "<LINK rel=STYLESHEET href=\"$style_sheet\" Type=\"text/css\">\n";
    if ($title)
    echo "<title>$title</title>\n";
    if (!$bgcolor)
    $bgcolor = "#FFFFFF";
    if (!$text_color)
    $text_color = "#000000";
    if (!$link_color)
    $link_color = "#0000FF";
    if (!$vlink_color)
    $vlink_color = "#FF0000";
    if (!$alink_color)
    $alink_color = "#000088";
    if ($background)
    $background = "background=\"$background\"";
    echo "<body bgcolor=\"$bgcolor\" text=\"$text_color\" link=\"$link_color\" vlink=\"$vlink_color\" alink=\"$alink_color\" $background>\n\n";
    }

    $recipient_in = split(',',$recipient);
    for ($i=0;$i<count($recipient_in);$i++) {
    $recipient_to_test = trim($recipient_in[$i]);
    if (!eregi("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3}$", $recipient_to_test)) {
    print_error("b>I NEED VALID RECIPIENT email ADDRESS ($recipient_to_test) TO CONTINUE</b>");
    }
    }
    if ($required)
    $require = $required;
    // handle the required fields
    if ($require) {
    // seperate at the commas
    $require = ereg_replace( " +", "", $require);
    $required = split(",",$require);
    for ($i=0;$i<count($required);$i++) {
    $string = trim($required[$i]);
    // check if they exsist
    if((!(${$string})) || (!(${$string}))) {
    // if the missing_fields_redirect option is on: redirect them
    if ($missing_fields_redirect) {
    header ("Location: $missing_fields_redirect");
    exit;
    }
    $require;
    $missing_field_list .= "<b>Missing: $required[$i]</b><br>\n";
    }
    }
    // send error to our mighty error function
    if ($missing_field_list)
    print_error($missing_field_list,"missing");
    }
    // check the email for validity
    if (($email) || ($email)) {
    $email = trim($email);
    if ($email)
    $email = trim($email);
    if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $email)) {
    print_error("your b>email address</b> is invalid");
    }
    $email = $email;
    }

    // check zipcodes for validity
    if (($S_PIN) || ($S_pin)) {
    $S_pin = trim($S_pin);
    if ($S_PIN)
    $S_pin = trim($S_PIN);
    if (!ereg("(^[0-9]{5})-([0-9]{4}$)", trim($S_pin)) && (!ereg("^[a-zA-Z][0-9][a-zA-Z][[:space:]][0-9][a-zA-Z][0-9]$", trim($S_pin))) && (!ereg("(^[0-9]{5})", trim($S_pin)))) {
    print_error("your <b>zip/postal code</b> is invalid");
    }
    }

    // check phone and Fax for validity
    //*if (($S_PHONE) || ($S_phone)) {
    //$S_phone = trim($S_phone);
    //if ($S_PHONE)
    // $S_phone = trim($S_PHONE);
    //if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $S_phone)) {
    // print_error("your <b>phone number</b> is invalid");
    // }
    //}
    //if (($S_FAX) || ($S_fax)) {
    // $S_fax = trim($S_fax);
    // if ($S_FAX)
    // $S_fax = trim($S_FAX);
    /// if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $fax_no)) {
    // print_error("your <b>fax number</b> is invalid");
    // }
    //}

    // prepare the content
    $content = parse_form($HTTP_POST_VARS);

    // check for a file if there is a file upload it
    if ($file_name) {
    if (!ereg("/$", $path_to_file))
    $path_to_file = $path_to_file."/";
    $location = $path_to_file.$file_name;
    copy($file,$location);
    unlink($file);
    $content .= "Uploaded File: ".$path_to_file.$file_name."\n";
    }

    // if the env_report option is on: get eviromental variables
    if ($env_report) {
    $env_report = ereg_replace( " +", "", $env_report);
    $env_reports = split(",",$env_report);
    $content .= "\n------ eviromental variables ------\n";
    for ($i=0;$i<count($env_reports);$i++) {
    $string = trim($env_reports[$i]);
    if ($env_reports[$i] == "REMOTE_HOST")
    $content .= "REMOTE HOST: ".$REMOTE_HOST."\n";
    else if ($env_reports[$i] == "REMOTE_USER")
    $content .= "REMOTE USER: ". $REMOTE_USER."\n";
    else if ($env_reports[$i] == "REMOTE_ADDR")
    $content .= "REMOTE ADDR: ". $REMOTE_ADDR."\n";
    else if ($env_reports[$i] == "HTTP_USER_AGENT")
    $content .= "BROWSER: ". $HTTP_USER_AGENT."\n";
    }
    }



    $content = "Business Enquiry
    \n=======================================\n";
    $content.= "Property Category : $category\n";
    $content.= "Name : $name\n";
    $content.= "Company : $cname\n";
    $content.= "Phone : $phone\n";
    $content.= "Street Address : $address\n";
    $content.= "City/ State : $city\n";
    $content.= "Zip/Postal Code : $pin\n";
    $content.= "Country : $country\n";
    $content.= "Email : $email\n";
    $content.= "Describe your requirements : $message\n";

    $content.= "=======================================\n";


    // if the subject option is not set: set the default
    if (!$subject)
    $subject = "Form submission";

    // send it off
    mail_it(stripslashes($content), stripslashes($subject), $from, $recipient);

    // if the redirect option is set: redirect them
    if ($redirect) {
    header ("Location: $redirect");
    exit;
    } else {
    print "Thank you for your submission\n";
    echo "<br><br>\n";
    exit;
    }
    ?>
     
    seoindia, Aug 26, 2006 IP
  2. seoindia

    seoindia Notable Member

    Messages:
    1,684
    Likes Received:
    101
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Will pay $10 by paypal one who solves the problem.....Kindly rectify the form and post it. I will check the form on net and if it works, will pay $10 instantly.
     
    seoindia, Aug 26, 2006 IP
  3. Cryogenius

    Cryogenius Peon

    Messages:
    1,280
    Likes Received:
    118
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to change the $from (second line) to be an email address on the same domain, and then your host will allow you to send emails to your Gmail account. However, there is a bug in the code. The function 'mail_it' accepts the $from address, but does not use it. I think that you really need to change the emdedded value from 'info@yashrealtors.com' to one that your domain host permits you to send emails from (i.e. on the same domain).

    In other words, replace this code:

    
    function mail_it($content, $subject, $from, $recipient) {
    mail($recipient, $subject, $content, "-f info@yashrealtors.com");
    }
    
    PHP:
    ...with this code:

    
    function mail_it($content, $subject, $from, $recipient) {
    mail($recipient, $subject, $content, "-f $from");
    }
    
    PHP:
    as well as changing the $from address on the at the very top of the script.

    Hope that helps...

    Cryo.
     
    Cryogenius, Aug 26, 2006 IP
  4. fscripting

    fscripting Banned

    Messages:
    288
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    try this

    
    <?
    $recipient ="mohitpuri@gmail.com";
    $from = $_POST['email'];
    $referers = array ('abc.com','www.abc.com');
    $version = "4.0";
    function print_error($reason,$type = 0) {
    global $version;
    build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
    if ($type == "missing") {
    ?>
    The form was not submitted for the following reasons:<p>
    <title></title><ul><?
    echo $reason."\n";
    ?></ul>
    Try again.<?
    } else {
    ?>
    The form was not submitted because :<p>
    <?
    }
    echo "<br><br>\n";
    echo "<small>Powered by Technosoft Services/a></small>\n\n";
    exit;
    }
    function check_referer($referers){
    if (count($referers)){
    $found = false;
    $temp = explode("/",getenv("HTTP_REFERER"));
    $referer = $temp[2];
    for ($x=0; $x < count($referers); $x++){
    if (ereg ($referers[$x], $referer)) {
    $found = true;
    }
    }
    if (!$found){
    print_error("You are coming from an <b>unauthorized domain.</b>");
    error_log("[form.php] Illegal Referer. (".getenv("HTTP_REFERER").")", 0);
    }
    return $found;
    } else {
    return true;
    }
    }
    if ($referers)
    check_referer($referers);
    
    function parse_form($array) {
    $reserved_keys[] = "MAX_FILE_SIZE";
    $reserved_keys[] = "required";
    $reserved_keys[] = "redirect";
    $reserved_keys[] = "email";
    $reserved_keys[] = "require";
    $reserved_keys[] = "path_to_file";
    $reserved_keys[] = "recipient";
    $reserved_keys[] = "subject";
    $reserved_keys[] = "bgcolor";
    $reserved_keys[] = "text_color";
    $reserved_keys[] = "link_color";
    $reserved_keys[] = "vlink_color";
    $reserved_keys[] = "alink_color";
    $reserved_keys[] = "title";
    $reserved_keys[] = "missing_fields_redirect";
    $reserved_keys[] = "env_report";
    if (count($array)) {
    while (list($key, $val) = each($array)) {
    $reserved_violation = 0;
    for ($ri=0; $ri<count($reserved_keys); $ri++) {
    if ($key == $reserved_keys[$ri]) {
    $reserved_violation = 1;
    }
    }
    // prepare content
    if ($reserved_violation != 1) {
    if (is_array($val)) {
    for ($z=0;$zcount($val);$z++) {
    $content .= "$key: $val[$z]\n";
    }
    } else {
    $content .= "$key: $val\n";
    }
    }
    }
    }
    return $content;
    }
    
    // mail the content we figure out in the following steps
    
    function mail_it($content, $subject, $from, $recipient) {
     mail($recipient, $subject, $content, "-f $from");
          } 
    
    // take in the body building arguments and build the body tag for page display
    function build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet) {
    if ($style_sheet)
    echo "<LINK rel=STYLESHEET href=\"$style_sheet\" Type=\"text/css\">\n";
    if ($title)
    echo "<title>$title</title>\n";
    if (!$bgcolor)
    $bgcolor = "#FFFFFF";
    if (!$text_color)
    $text_color = "#000000";
    if (!$link_color)
    $link_color = "#0000FF";
    if (!$vlink_color)
    $vlink_color = "#FF0000";
    if (!$alink_color)
    $alink_color = "#000088";
    if ($background)
    $background = "background=\"$background\"";
    echo "<body bgcolor=\"$bgcolor\" text=\"$text_color\" link=\"$link_color\" vlink=\"$vlink_color\" alink=\"$alink_color\" $background>\n\n";
    }
    
    $recipient_in = split(',',$recipient);
    for ($i=0;$i<count($recipient_in);$i++) {
    $recipient_to_test = trim($recipient_in[$i]);
    if (!eregi("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3}$", $recipient_to_test)) {
    print_error("b>I NEED VALID RECIPIENT email ADDRESS ($recipient_to_test) TO CONTINUE</b>");
    }
    }
    if ($required)
    $require = $required;
    // handle the required fields
    if ($require) {
    // seperate at the commas
    $require = ereg_replace( " +", "", $require);
    $required = split(",",$require);
    for ($i=0;$i<count($required);$i++) {
    $string = trim($required[$i]);
    // check if they exsist
    if((!(${$string})) || (!(${$string}))) {
    // if the missing_fields_redirect option is on: redirect them
    if ($missing_fields_redirect) {
    header ("Location: $missing_fields_redirect");
    exit;
    }
    $require;
    $missing_field_list .= "<b>Missing: $required[$i]</b><br>\n";
    }
    }
    // send error to our mighty error function
    if ($missing_field_list)
    print_error($missing_field_list,"missing");
    }
    // check the email for validity
    if (($email) || ($email)) {
    $email = trim($email);
    if ($email)
    $email = trim($email);
    if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $email)) {
    print_error("your b>email address</b> is invalid");
    }
    $email = $email;
    }
    
    // check zipcodes for validity
    if (($S_PIN) || ($S_pin)) {
    $S_pin = trim($S_pin);
    if ($S_PIN)
    $S_pin = trim($S_PIN);
    if (!ereg("(^[0-9]{5})-([0-9]{4}$)", trim($S_pin)) && (!ereg("^[a-zA-Z][0-9][a-zA-Z][[:space:]][0-9][a-zA-Z][0-9]$", trim($S_pin))) && (!ereg("(^[0-9]{5})", trim($S_pin)))) {
    print_error("your <b>zip/postal code</b> is invalid");
    }
    }
    
    // check phone and Fax for validity
    //*if (($S_PHONE) || ($S_phone)) {
    //$S_phone = trim($S_phone);
    //if ($S_PHONE)
    // $S_phone = trim($S_PHONE);
    //if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $S_phone)) {
    // print_error("your <b>phone number</b> is invalid");
    // }
    //}
    //if (($S_FAX) || ($S_fax)) {
    // $S_fax = trim($S_fax);
    // if ($S_FAX)
    // $S_fax = trim($S_FAX);
    /// if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $fax_no)) {
    // print_error("your <b>fax number</b> is invalid");
    // }
    //}
    
    // prepare the content
    $content = parse_form($HTTP_POST_VARS);
    
    // check for a file if there is a file upload it
    if ($file_name) {
    if (!ereg("/$", $path_to_file))
    $path_to_file = $path_to_file."/";
    $location = $path_to_file.$file_name;
    copy($file,$location);
    unlink($file);
    $content .= "Uploaded File: ".$path_to_file.$file_name."\n";
    }
    
    // if the env_report option is on: get eviromental variables
    if ($env_report) {
    $env_report = ereg_replace( " +", "", $env_report);
    $env_reports = split(",",$env_report);
    $content .= "\n------ eviromental variables ------\n";
    for ($i=0;$i<count($env_reports);$i++) {
    $string = trim($env_reports[$i]);
    if ($env_reports[$i] == "REMOTE_HOST")
    $content .= "REMOTE HOST: ".$REMOTE_HOST."\n";
    else if ($env_reports[$i] == "REMOTE_USER")
    $content .= "REMOTE USER: ". $REMOTE_USER."\n";
    else if ($env_reports[$i] == "REMOTE_ADDR")
    $content .= "REMOTE ADDR: ". $REMOTE_ADDR."\n";
    else if ($env_reports[$i] == "HTTP_USER_AGENT")
    $content .= "BROWSER: ". $HTTP_USER_AGENT."\n";
    }
    }
    
    
    
    $content = "Business Enquiry
    \n=======================================\n";
    $content.= "Property Category : $category\n";
    $content.= "Name : $name\n";
    $content.= "Company : $cname\n";
    $content.= "Phone : $phone\n";
    $content.= "Street Address : $address\n";
    $content.= "City/ State : $city\n";
    $content.= "Zip/Postal Code : $pin\n";
    $content.= "Country : $country\n";
    $content.= "Email : $email\n";
    $content.= "Describe your requirements : $message\n";
    
    $content.= "=======================================\n";
    
    
    // if the subject option is not set: set the default
    if (!$subject)
    $subject = "Form submission";
    
    // send it off
    mail_it(stripslashes($content), stripslashes($subject), $from, $recipient);
    
    // if the redirect option is set: redirect them
    if ($redirect) {
    header ("Location: $redirect");
    exit;
    } else {
    print "Thank you for your submission\n";
    echo "<br><br>\n";
    exit;
    }
    ?>
    
    Code (markup):
    If it doesnt work pm me
     
    fscripting, Aug 27, 2006 IP
  5. seoindia

    seoindia Notable Member

    Messages:
    1,684
    Likes Received:
    101
    Best Answers:
    0
    Trophy Points:
    200
    #5
    Still not working.....
     
    seoindia, Aug 29, 2006 IP
  6. seoindia

    seoindia Notable Member

    Messages:
    1,684
    Likes Received:
    101
    Best Answers:
    0
    Trophy Points:
    200
    #6
    Still looking for solution and willing to pay if the problem get solved...
     
    seoindia, Aug 31, 2006 IP