0

I want to style the mail i get from a contact form from my website. Right now it just sends everything in one big mess, and i wanted it to be aligned pretty in some tables and with a header title and so on.

Here is my form:

@if(ShowForm)
{

<div class="form">
    <h3>Find prisen </h3>
    <p>på din flytning ved at udfylde denne</p> 

   <form method="post">

   <div class="controls">        
                <input class="span12" type="text" id="fromdest" name="fromdest" value="@PostedFromdest" placeholder="Fra-flytningsadresse" required />
        </div>

        <div class="controls controls-row">        
                <input class="span4" type="text" id="zip" name="zip" value="@PostedZip" placeholder="Post nr" required />            
                <input class="span8" type="text" id="city" name="city" value="@PostedCity" placeholder="By" required />             
        </div>

                    <hr size="0,2">

           <div class="controls">        
                <input class="span12" type="text" id="todest" name="todest" value="@PostedTodest" placeholder="Flytter til adresse" required />            
        </div>

        <div class="controls controls-row">        
                <input class="span4" type="text" id="zipt" name="zipt" value="@PostedZipt" placeholder="Post nr" required />            
                <input class="span8" type="text" id="cityt" name="cityt" value="@PostedCityt" placeholder="By" required />            
            </div>
            <div class="controls controls-row">        
                <input class="span4" type="text" id="areal" name="areal" value="@PostedAreal" placeholder="Areal" required />            
                <select class="span8" name="furniture">
                <option value="Alm. Møblering">Alm. Møblering</option>
                <option value="Tæt Møbleret">Tæt Møbleret</option>
                <option value="Lidt Møbleret">Lidt Møbleret</option>
                </select>
        </div>

        <div class="controls controls-row">        
                <input class="span4" type="text" id="rum" name="rum" value="@PostedRum" placeholder="Rum" required />           
                <select class="span8" name="men">
                <option value="2 flyttemænd">2 flyttemænd</option>
                <option value="3 flyttemænd">3 flyttemænd</option>
                <option value="4 flyttemænd">4 flyttemænd</option>
                <option value="5 flyttemænd">5 flyttemænd</option>
                <option value="6 flyttemænd">6 flyttemænd</option>
                </select> 
        </div>
                    <hr size="0,2">

        <div class="controls">
                <input class="span12" type="text" id="name" name="name" value="@PostedName" placeholder="Dit navn" required />
            </div>            
            <div class="controls">
                <input class="span12" type="text" id="email" name="email" value="@PostedEmail" placeholder="Email adresse" required />
            </div>
        <div class="controls controls-row">
                <input class="span12" type="text" id="phone" name="phone" value="@PostedPhone" placeholder="Telefon nummer" required  />
            </div>
        <div class="controls">
                <label class="checkbox"><input type="checkbox" id="callme" name="callme"> Ring mig op</label>
        </div>

        <div class="controls">       
                <textarea class="span12" id="message" name="message" value="@PostedMessage" placeholder="Kommentar" required ></textarea>
        </div>
        <div class="controls center">                   
            <div class="span12">
                <input type="text" name="url" />           
                <input type="submit" value="Beregn min flyttepris" class="btn btn-primary" />
            </div>
        </div>        
    </form> 

    <script type="text/javascript">$('input[name="url"]').hide();</script>
</div>

}
</div>

When I send the message i use this line of code:

umbraco.library.SendMail(String.Concat("no-reply@", host), contactRecipent, contactSubject, bodyText, false);

bodyText being the input from the form.

I read on the internet that i could try styling the mail with html, so i created this instead of bodyText.

bodyText = @"<html>
                  <head><title>Henvendelse modtaget fra hjemmesiden</title></head>
                  <body>
      <table>
     <tr><td>Flytter fra:</td><td>'.PostedFromdest.','.PostedZip.''.PostedCity.'</td></tr>
     <tr><td>Flytter til:</td><td>'.PostedTodest.','.PostedZipt.''.PostedCityt.'</td></tr>
     <tr><td>Indretning:</td><td>'.PostedFurniture.'</td></tr>
     <tr><td>Antal rum:</td><td>'.PostedRum.'</td></tr>
     <tr><td>Bemanding:</td><td>'.PostedMen.'</td></tr>
     <tr><td>Navn:</td><td>'.PostedName.'</td></tr>
     <tr><td>Email:</td><td>'.PostedEmail.'</td></tr>
     <tr><td>Telefon:</td><td>'.PostedPhone.'</td></tr>
     <tr><td>Ringes op:</td><td>'.PostedCallme.'</td></tr>
     <tr><td>Kommentar:</td><td>'.PostedComment.'</td></tr>
      </table>
    </body>
    </html>"
         ;

but now it just sends the raw html, without formatting it.

Can anyone help me?

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
  • what do you think is that last `bool` argument in `umbraco.library.SendMail`? – Mat J Dec 04 '13 at 13:11
  • You supply a `false` as last param of `umbraco.library.SendMail`. What is that param (I don't know Umbraco)? If it is "send as HTML", then set to true. – Hans Kesting Dec 04 '13 at 13:14

1 Answers1

2

You need to specify that you are sending a Html formatted mail when calling the SendMail.

umbraco.library.SendMail(
                          String.Concat("no-reply@", host), 
                          contactRecipent, 
                          contactSubject, 
                          bodyText, 
                          true             //<--- this should be true if you want to send html mail
                         );

Reference

Mat J
  • 5,422
  • 6
  • 40
  • 56