Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    how can you make mailFormat.Html in this code

    Hi All,

    The code below which sends a comment email to the site owner as well as a thank you email to user does so just fine but the text in the sent mail is shall we say in a text format and web mail services won't render tags like <b> bold or any HTML formatting in the body of the mail.

    I want to change that basic text format to allow the body to be HTML in the site owner mail and the users thank you mail.
    I have come across this code.....
    Code:
    mail.BodyFormat = MailFormat.Html
    and would like to know how, if possible, it could be added into the main code below to do that.

    PHP Code:
    <?php



        
    # This variable will be used if the destination_email variable is not set on the form.
        
    $default_destination_email "a@b.com";

        
    # The name of your website
        
    $site_name "a site";

        
    # The default followup URL in case one isn't supplied on the form.
        
    $default_followup_url "anotherpage.php";

        
    # The value of this variable will be displayed if the followup_url is not specified.
        
    $default_response "Thank you for your comment.";



    function 
    error($code "No Error Specified"$display false$terminate false)
    {
        global 
    $default_destination_email;
        
    mail("$default_destination_email","FORM_CONTACT Script Error","Warning!
    The FORM_CONTACT script on your site generated the following error:
    $code"
    ,"From: $default_destination_email");

        if(
    $display) echo $code;

        if(
    $terminate) exit;
    }



    if(
    $_POST)
    {
        if(!
    $_POST['destination_email'])
        {
            
    $_POST['destination_email'] = $default_destination_email;
        }
        if(
    $_POST['destination_email'] == "your@emailaddress.here")
        {
            
    error("Script Error:  This form processing script has not yet been correctly set up.<br>Please contact the webmaster."truetrue);
        }

        
    $arrexclude = array("Submit""destination_email""required""followup_url");
        if(
    $_POST['required']){
            
    $a_required explode(" ",$_POST['required']);
            for (
    $n 0$n count($a_required); $n++)
            {
                if(!
    $_POST[$a_required[$n]])
                {
                    echo 
    "You must enter a value for: $a_required[$n]";
                    exit;

                }
            }
        }

        
    $msg "";
        while (list(
    $key$value) = each($_POST)) {
            
    $exclude false;
            for (
    $n 0$n <= count($arrexclude); $n++) {
                if (
    $key == $arrexclude[$n]) {
                    
    $exclude true;
                }
            }

            if (
    $exclude == false) {
                
    $key strtoupper($key);
                
    $msg .= "\n\n".$key.":  ";
                if (
    is_array($value)) {
                    
    $msg .= implode("\n"$value);
                } else {
                    
    $msg .= $value;
                }
            }
        }

        
    $msg trim(stripslashes($msg));
        
    $badStrings = array("Content-Type:",
                             
    "MIME-Version:",
                             
    "Content-Transfer-Encoding:",
                             
    "bcc:",
                             
    "cc:");

        foreach(
    $badStrings as $v2){

            if(
    strpos(strtolower($_POST['fromwording_email']), strtolower($v2)) !== false){
                
    error("Website Form Hack Attempt on Destination Email: '$fromwording_email'");
                
    header("HTTP/1.0 403 Forbidden");
                    exit;
            }
            if(
    strpos(strtolower($_POST['destination_email']), strtolower($v2)) !== false){
                
    error("Website Form Hack Attempt on Destination Email: '$destination_email'");
                
    header("HTTP/1.0 403 Forbidden");
                    exit;
            }
            if(
    strpos(strtolower($_POST['subject']), strtolower($v2)) !== false){
                
    error("Website Form Hack Attempt on Subject: '$subject'");
                
    header("HTTP/1.0 403 Forbidden");
                    exit;
            }
            if(
    strpos(strtolower($_POST['Customer_Email']), strtolower($v2)) !== false){
                
    error("Website Form Hack Attempt on Email: '$email'");
                
    header("HTTP/1.0 403 Forbidden");
                    exit;
            }
            if(
    strpos(strtolower($_POST['response_email']), strtolower($v2)) !== false){
                
    error("Website Form Hack Attempt on Response_email: '$response_email'");
                
    header("HTTP/1.0 403 Forbidden");
                    exit;
            }
            if(
    strpos(strtolower($_POST['response_name']), strtolower($v2)) !== false){
                
    error("Website Form Hack Attempt on Response_name: '$response_name'");
                
    header("HTTP/1.0 403 Forbidden");
                    exit;
            }
        }

        
    $fromwording_email preg_replace("/[\r|\n]*/i"""$_POST['fromwording_email']);
        
    $destination_email preg_replace("/[\r|\n]*/i"""$_POST['destination_email']);
        
    $email preg_replace("/[\r|\n]*/i"""$_POST['Customer_Email']);
        
    $subject preg_replace("/[\r|\n]*/i"""$_POST['subject']);
        
    $response_email preg_replace("/[\r|\n]*/i"""$_POST['response_email']);
        
    $response_name preg_replace("/[\r|\n]*/i"""$_POST['response_name']);

        
    mail("$destination_email","$subject","$msg\n","FROM: $destination_email");

        
    $autoresponse_file preg_replace("/[\r|\n]*/i"""$_POST['autoresponse_file']);
        
    $cm_subject preg_replace("/[\r|\n]*/i"""$_POST['cm_subject']);

        if(
    $autoresponse_file && $email)
        {
            if(
    strpos(" $autoresponse_file""..")) error("AutoResponse File Hack Detected.  Attempted to download: '$autoresponse_file'"falsetrue);


            if(@
    $file implode(file("autoresponse/$autoresponse_file"), ""))
            {
                
    $fp 0;
                while(
    strpos(" $file""{~"$fp))
                {
                    
    $fp strpos($file"{~"$fp);
                    
    $ep strpos($file"~}"$fp)+2;
                    
    $temp substr($file$fp$ep-$fp);
                    
    $temp2 substr($temp2strlen($temp)-4);

                    if(
    strpos("-$temp"" "))
                    {
                        
    error("You may not have spaces in variable names in the autoresponse files.
        The file containing the error is: $autoresponse_file"
    );
                        break;
                    }

                    if(
    strpos("-$temp""\n"))
                    {
                        
    error("You may not have newline characters in the autoresponse files.
        The file containing the error is: $autoresponse_file"
    );
                        break;
                    }

                    
    $file str_replace($temp$_POST[$temp2], $file);
                }
                
    mail("$email","$site_name: $cm_subject","$file","From: $fromwording_email");
            }
            else
            {
                
    error("The following form asked for a non-existent autoresponse to be sent:\n$HTTP_REFERER\n\nThe autoresponse file that it asked for was:\n$autoresponse_file");
            }
        }

        if(!
    $_POST['followup_url']) $_POST['followup_url'] = $default_followup_url;
        if(
    $_POST['followup_url'] != "http://www.your site name.com/thanks.html")
            
    header("Location: " $_POST['followup_url']);
        else
            echo 
    "$default_response";

    }
    ?>

    Martin.
    Last edited by SpidersWebHelp; 04-29-2014 at 11:53 PM.

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    You have to use headers to specify the (Content-)type as text/html

    PHP Code:
    $headers 'Content-type: text/html';
    mail($to$subject$message$headers); 
    This will allow you to use those tags in the messages.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •