Sending form to email in webmatrix

434 Views Asked by At

I have a question regarding emails, i want to send the whole contact form to email, and in this tutorial http://www.asp.net/web-pages/tutorials/email-and-search/11-adding-email-to-your-web-site it has almost everything except this line in code

// Send email
WebMail.Send(to: customerEmail,
    subject: "Help request from - " + customerName,
    body: customerRequest

);

}

i do not understand how to edit it,now the thing is it is working but only sending me customerRequest in email because now there is a form with more details and it is only sending customerRequest part not email , number, items and other categories, so kindly assist how to send the whole form or other columns through this. Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

The customerRequest variable can contain any string you want it to contain. In the tutorial, it represents the value of the customerRequest form field. You can add other fields to the form and use their values to build up the body of the email. For example, you can add a partNumber field:

Your name:

<div>
    Your email address:
    <input type="text" name="customerEmail" />
</div>
<div>
    Part Number:
    <input type="text" name="partNumber" />
</div>

<div>
    Details about your problem: <br />
    <textarea name="customerRequest" cols="45" rows="4"></textarea>
</div>

<div>
    <input type="submit" value="Submit" />
</div>

And in the server-side code, add that to the body:

@{
    var customerName = Request["customerName"];
    var customerEmail = Request["customerEmail"]; 
    var customerRequest = Request["customerRequest"];
    var partNumber = Request["partNumber"];
    var errorMessage = "";
    var debuggingFlag = false;
    //etc
}

This is how you could concatenate the values:

WebMail.Send(to: customerEmail,
            subject: "Help request from - " + customerName,
            body: "Part Number: " + partNumber + "\n\n" + customerRequest
        );