I have made a control that creates an electronic invite to an event. The user inputs their information into textboxes and the system gathers that information, adds it to the HTML for the email and then sends it.
I am encountering an error when I combine all the parts. My code is below.
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(YourEmailBox.Text, YourNameBox.Text);
message.From = fromAddress;
message.To.Add(FriendEmailBox.Text);
message.Subject = EmailSubject;
message.IsBodyHtml = true;
message.Body = "<html>" + string.Format(EmailBody, YourNameBox.Text, PersonalNoteBox.Text) + "</html>";
smtpClient.Send(message);
YourNameBox.Text = YourEmailBox.Text = FriendNameBox.Text = FriendEmailBox.Text = PersonalNoteBox.Text = string.Empty;
Label1.Text = "Email Successfully sent!";
}
It is giving me the input string was not in a correct format error on this line:
message.Body = "<html>" + string.Format(EmailBody, YourNameBox.Text, PersonalNoteBox.Text) + "</body></html>";
Will you please help me out?
Why not just do:
message.Body =
string.Format("<html>{0}</html>",EmailBody.Text)I don’t get why you have 3 arguments passed to string.Format, for example,
"<html>" + string.Format("3","4","5") + "</html>"will produce<html>3</html>