Outputting Bold format in contact mail?

Discussion in 'PHP' started by Kayz, Oct 8, 2008.

  1. #1
    Hi i have a contact form and it works fine, for e.g

    Firstname: Mr.xyz
    Surname: abc

    However what i want the output to look like within my email is

    Firstname: Mr.xyz
    Surname: abc

    How can i acheive this? Ive been working so hard all day but still cannot get it to work?

    Here is the small PHP form im using:

    <?php
    
    $receiver = 'me@mymail.com';
    $subject = 'Web Mail';
    $fromemail = 'mail@mydomain.com';
    
    $err_msg = '';
    if((!$name) || (!$email) || (!$comments)){
            $err_msg = '<br />The following fields are missing, please insure you have filled out each field <br /><br />';
    
       if(!$name){
            $err_msg .= "* Your Name<br />";
        }
       if(!$email){
            $err_msg .= "* Your Email Address<br />";
       }
       if(!$comments){
            $err_msg .= "* Your Comments<br />";
       }
       include 'index.php';
    
     exit();
    }
    
    $arr= array();
    
    	$arr[0] = "\n Nature of Inquiry: ";
    	$arr[1] = $Inquiry;
    	$arr[2] = "\n Name is: ";
    	$arr[3] = $name;
    	$arr[4] = "\n forumusername is: ";
    	$arr[5] = $forumusername;
    	$arr[6] = "\n Email is: ";
    	$arr[7] = $email;
    	$arr[8] = "\n Comments are: ";
    	$arr[9] = $comments;
    
    $content = ($arr[0]. $arr[1] . $arr[2] . $arr[3] . $arr[4] . $arr[5] . $arr[6] . $arr[7] . $arr[8] . $arr[9]);
    
    mail("$receiver", "$subject!", "$content", "From: $fromemail");
    header( "Location: thankyou.html" ); 
    
    ?>
    PHP:

    Any help would be much appreciated.
     
    Kayz, Oct 8, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    You need to send your email in HTML, with HTML headers and then you can use <font style="anyfont">text</font>
     
    EricBruggema, Oct 8, 2008 IP
  3. Kayz

    Kayz Active Member

    Messages:
    245
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #3
    What do you think i need to do in the above codes to enable this?
     
    Kayz, Oct 9, 2008 IP
  4. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Here is the function in the manual:

    http://us.php.net/manual/en/function.mail.php

    Scroll down the page and eventually you will see an example of allowing html in the email. However I am a big fan of PHPMailer, especially the SMTP functions. With PHPMailer you can easily add html support, even give the non html version as well as easily attach files to your email. Give it a look if you need more functionality in emailing:

    http://phpmailer.codeworxtech.com/
     
    Sillysoft, Oct 9, 2008 IP
  5. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yep, like this (if you use the php mail function)
    
    		$to = 'address@target.com';
    		$subject ='bold text';
    		$body = '<strong>bold text</strong>';
    
    		$headers =  "From: email@website.com\r\n";
    		$headers .= "Content-type: text/html\r\n";
    
    		if (mail($to, $subject, $body, $headers)) {
    		  echo "<p>Message successfully sent!</p>";
    		 } else {
    		  echo "<p>Message delivery failed...</p>";
    		 }
    PHP:

    you define the content as html with an additional header :
    $headers .= "Content-type: text/html\r\n";
    PHP:
    and add the header as fourth variable to the mail function
    if (mail($to, $subject, $body, $headers)) {


    some others:
    http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php
    a function to add plain text and html in one go :
    http://code.web-max.ca/misc_htmlemail.php
     
    juust, Oct 9, 2008 IP