设置从C#表单发送邮件的样式?

时间:2013-12-04 13:06:29

标签: c# email umbraco styling

我想从我的网站上的联系表单中获取邮件的样式。 现在它只是将所有内容都发送到一个大混乱中,我希望它在一些表格中以及标题标题等对齐。

这是我的表格:

@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>

当我发送消息时,我使用这行代码:

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

bodyText是表单的输入。

我在网上看到我可以尝试使用html设置邮件样式,所以我创建了这个而不是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>"
         ;

但现在它只发送原始html,而不进行格式化。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

您需要在调用Html时指定发送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