Posted: 7/5/2011
Hey there!
Everything is working fine (even send email button working but there is no body). I need to know how to interact every input tag such as name, email as well as select tag and table tag to Contact.aspx.cs (behind code). If doing this, it should be readable in gmail account - example of body:
Name: xxxxx
Email: xxxx
Order: xxxx
Description: xxxxx
Please look at my below codes and please help me insert some codes in Contact.aspx.cs. Your help much appreciated. Thank you!
Here is Contact.aspx:
<label>Name: <input id="txtName" type="text" name="name" size="30" placeholder="" required /> </label>
<label>E-mail: <input id="txtEmail" type="text" name="email" size="30" placeholder="" required /> </label>
<select name="order" size="12" multiple="multiple" style="width:330px;" id="dlist1" onchange="swapImage1()"> <optgroup label="Sow Seeds of Love"> <option selected="selected" value="Images/NoneImage.gif">None</option> <option data-card="32.00" data-memo="62.00" data-tags1="1.80" data-tags4="8.50" data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/SowSeeds/Peace01_pink.jpg">Peace</option> <option data-card="----" data-memo="----" data-tags1="----" data-tags4="----" data-key="----" data-fridge="----" data-flower_sachet="12.00" value="Images/Order_names/SowSeeds/FlowerSeedSachet01_two girls.jpg">Flower Seed Sachet</option> </optgroup> <optgroup label="Goosebumps Vintage A"> <option data-card="32.00" data-memo="62.00" data-tags1="1.80" data-tags4="----" data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/GoosebVA/GoosebumpVA_blue.jpg">Blue</option> <option data-card="32.00" data-memo="62.00" data-tags1="1.80" data-tags4="----" data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/GoosebVA/GoosebumpVA_green.jpg">Green</option> </optgroup>
</select>
<table> <tr> <td class="style3"><label><input type="checkbox" name="description" value="Card A6" id="description" /> Card A6 (blank)</label></td> <td id="price_card"></td> </tr> <tr> <td class="style3"><label><input type="checkbox" name="description" value="Memo Book A6" id="description" /> Memo Book A6</label></td> <td id="price_memo"></td> </tr>
</table>
<p> <textarea id="txtComment" name="comment" cols="40" rows="7"></textarea> </p>
<asp:Button ID="Send" runat="server" Text="Send Email" onclick="Send_Click" /> <input type= "reset" value="Clear" />
Behind code - Contact.aspx.cs
protected void Send_Click(object sender, EventArgs e) { string from = "myemail@gmail.com"; //Replace this with your own correct Gmail Address string to = "myemail@gmail.com"; //Replace this with the Email Address to whom you want to send the mail MailMessage mail = new MailMessage(); mail.To.Add(to); mail.From = new MailAddress(from, "Ellie Rose", System.Text.Encoding.UTF8); mail.Subject = "Customer Order from Ellie Rose Website"; mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "This is Email Body Text"; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; mail.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); //Add the Creddentials- use your own email id and password client.Credentials = new System.Net.NetworkCredential(from, "my password"); client.Port = 587; // Gmail works on this port client.Host = "smtp.gmail.com"; client.EnableSsl = true; //Gmail works on Server Secured Layer try { client.Send(mail); } catch (Exception ex) { Exception ex2 = ex; string errorMessage = string.Empty; while (ex2 != null) { errorMessage += ex2.ToString(); ex2 = ex2.InnerException; } HttpContext.Current.Response.Write(errorMessage); } //
Hi Natalie,
Try to set the flag "IsBodyHtml = true'.
Here is a code snippet from a project of mine:
public static bool SendEmail(string recipientEmail, string subject, string body) { bool _result = true; var _smtp = new SmtpClient(s_SmtpClient); _smtp.Credentials = new NetworkCredential(s_FromEmail, s_Password); System.Net.Mail.MailMessage _message = new System.Net.Mail.MailMessage(); MailAddress _addressFrom = new MailAddress(s_FromEmail); MailAddress _addressTo = new MailAddress(recipientEmail); _message.Subject = subject ; _message.From = _addressFrom; _message.To.Add(_addressTo); _message.IsBodyHtml = true; _message.Body = body; try { _smtp.Send(_message); } catch { _result = false; } return _result; }
Best Regards,
Gjorgji