Page 1 of 3

ContactUs Control

Posted: Fri Aug 15, 2008 7:39 am
by mazhar
This is a simple sample that how to write a Feedback or contact control for AbleCommerce using the AbleCommerce configured SMTP settings. Please download the attachment for the source code of the control. The control exposes a single property SendTo that is used to specify the Email address where you want to receive the Emails sent by the control. You can use it like any other control

Code: Select all

[[ConLib:ContactUs SendTo="info@yourstore.com"]]
Note: If you don't configured this SendTo property the Email will be sent to your default Email address which you configured for the store in the SMTP settings.

ContactUs control version supporting AbleCommerce 7.0.8 Gold is avilable here viewtopic.php?f=47&t=17102

[SCREEN SHOT]

Re: ContactUs Control

Posted: Fri Aug 15, 2008 9:42 am
by Mike718NY
Thanks for that. That's very useful.

But I would add a "Subject" line also.
Or maybe get rid of "Name". People will usually put that in the message.

Re: ContactUs Control

Posted: Fri Aug 15, 2008 10:32 am
by Robbie@FireFold
Beautiful.

I have this same control in my current software. You would be shocked how many customers use it - I assume because its 'easy.'

Thanks!

Re: ContactUs Control

Posted: Mon Aug 18, 2008 1:04 pm
by harris43
Where can you alter where the contents of this message is sent to?
I don't see where it is sending the form.

Re: ContactUs Control

Posted: Mon Aug 18, 2008 1:06 pm
by harris43
oops. Now I see it above.

Re: ContactUs Control

Posted: Fri Oct 24, 2008 9:00 am
by mazhar
This is an update to existing contact us control. In order to avoid spams we can extend the contact us control to support the captcha code. I have used the captcha available with AbleCommerce. In order to install the control just extract the control files and place them in the ConLib. The control Supports an EnableCaptcha property which you can set to True/False to enable or disable captcha. By default the captcha is enabled. You can change the mail subject by using Subject property. You can set SendTo property to specify the Email address where you want to receive the messages. If you don't specify this property the Email will be sent to store's default Email address. For example you can place the control in some store page as bellow

Code: Select all

[[ConLib:ContactUs SendTo="info@mystore.com" ]]

Re: ContactUs Control

Posted: Tue Nov 04, 2008 6:12 am
by mazhar
You can easily incorporate the attachment ability in the contactus control. Here is the modified version of the ContactUs control with attachment support

Re: ContactUs Control

Posted: Sat Nov 22, 2008 9:24 pm
by Jaz
I must be doing something wrong. I have tried to apply this Contact Us control and I can't get it to work. I have tried it in the conlib folder and in the custom folder.

I am putting it in the "Sidebar 2" section in the "Shopping Bar 1"

Code: Select all

[[ConLib:ContactUs SendTo="david@trickconcepts.com" ]]
[[ConLib:MiniBasket]]
[[ConLib:custom/RecentlyViewed]]


The control works fine and says that the message is sent, but I never receive it. I have tried chaning the SendTo Email address and removing it all together, but it makes no difference.

Any Suggestions?

Thanks,

Jaz

Re: ContactUs Control

Posted: Sat Nov 22, 2008 9:42 pm
by Jaz
I just found out something else. My shipping calculator had not been working right. I had the minibasket in the Sidebar 2 with the ContactUs Control. When I set the ContactUs control to Visible="false" the shipping calculator started to work again?

Do you think this is related, or just a coincidence?

If this is the problem, how do I adjust the ContactUs controls to work in the Sidebar2? If I can't adjust it, where do I need to put the ContactUs control?

Re: ContactUs Control

Posted: Mon Nov 24, 2008 8:15 am
by mazhar
Which version of the control you are using, I mean the simple one, with captcha or the the one with attachment facility.

Re: ContactUs Control

Posted: Mon Nov 24, 2008 2:33 pm
by Jaz
I have tried the second 2 - I'll try the simple one.

Re: ContactUs Control

Posted: Mon Nov 24, 2008 2:59 pm
by Jaz
I just tried the simple one in both the right side bar and the main content area. I can't get anthing to send. It tells me the message is sent. I have tried it in bot custom and in the conlib folder. Here is the syntax I am using.

Code: Select all

[[ConLib:custom/ContactUs SendTo="david@trickconcepts.com" Visible="true"]]
[[ConLib:custom/MiniBasket]]
[[ConLib:custom/RecentlyViewed]]

Re: ContactUs Control

Posted: Mon Nov 24, 2008 7:36 pm
by Jaz
I got it working. It was a SMTP Error.

Thanks,

Re: ContactUs Control

Posted: Mon Dec 22, 2008 11:23 am
by wave_werks
mazhar wrote:You can set SendTo property to specify the Email address where you want to receive the messages. If you don't specify this property the Email will be sent to store's default Email address.

Code: Select all

[[ConLib:ContactUs SendTo="info@mystore.com" ]]
I'm using this control as it was provided here as well as a heavily modified version. Each is on its own page. One of the forms is ok to send to the default email address but I'd like the other to be sent to an address specified in the control. I've added the alternate email address as you have shown above but still only receive the email at the default email address. Is there somewhere else that I need to make a change?

Re: ContactUs Control

Posted: Mon Dec 22, 2008 12:04 pm
by mazhar
I'm using this control as it was provided here as well as a heavily modified version. Each is on its own page. One of the forms is ok to send to the default email address but I'd like the other to be sent to an address specified in the control. I've added the alternate email address as you have shown above but still only receive the email at the default email address. Is there somewhere else that I need to make a change?
I have checked the above two versions of control by providing different Email addresses in SendTo property and they worked fine. Have you customized something?

Check the below code it is responsible for Email address selection. If you haven't provided something for SendTo property then it will pick the store default address other wise it will send Email to the address specified in the SendTo property.

Code: Select all

 if (String.IsNullOrEmpty(SendTo))
            mailMessage.To.Add(settings.DefaultEmailAddress);
        else
            mailMessage.To.Add(SendTo);

Re: ContactUs Control

Posted: Mon Dec 22, 2008 12:35 pm
by wave_werks
mazhar wrote:
Check the below code it is responsible for Email address selection. If you haven't provided something for SendTo property then it will pick the store default address other wise it will send Email to the address specified in the SendTo property.

Code: Select all

 if (String.IsNullOrEmpty(SendTo))
            mailMessage.To.Add(settings.DefaultEmailAddress);
        else
            mailMessage.To.Add(SendTo);
I'm a complete and total novice at this stuff. How do I add my preferred SendTo address in that part of the code? I'm not exactly sure of how to modify it without messing it all up and making it unusable.

I've already added my preferred address the SendTo in this section:

Code: Select all

[[ConLib:ContactUs SendTo="info@mystore.com" ]]

Re: ContactUs Control

Posted: Mon Dec 22, 2008 12:38 pm
by mazhar
Then the control must send the Email address to that address you specified in the SendTo property.

Re: ContactUs Control

Posted: Mon Dec 22, 2008 12:51 pm
by wave_werks
mazhar wrote:Then the control must send the Email address to that address you specified in the SendTo property.
That's what I thought but it definitely does not. I just changed the unmodified version to send to an alternate address and it still sends to the default address and not to the alternate address.

There is nowhere in the .ascx or the ascx.cs file that needs to have the alternate address added?

Re: ContactUs Control

Posted: Fri Dec 26, 2008 4:11 pm
by Tomgard
What I am finding is that the users of this control are submitting their request multiple times becuase they are 'unsure' if the message has been sent.

Is it possible to add in a successful redirect page upon submission of a contact request?

I created an auto reply based on the 'sendto' address but this did not help becuase of the delay in the email client.

Re: ContactUs Control

Posted: Fri Dec 26, 2008 5:39 pm
by jmestep
On a contact form I made, I moved the message up above the send button so it would be more obvious that it was sent. I also cleared the fields in the form after the message was sent. I think you could do that in this one in this section of code:
try
{
MessageLabel.Text = "Message Sent";
MessageLabel.CssClass = "goodCondition";
EmailClient.Send(mailMessage);
[Add this]
Email.Text="";
Name.Text="";
Comment.Text="";

}

Maybe with combination of both, the customer would realize that the message had been sent without your having to make a confirmation page.
[edited to capital T in Text]

Re: ContactUs Control

Posted: Tue Dec 30, 2008 10:28 am
by mazhar
If you have some page which you want to show to customer on successful submission of message, for this you can just put a Response.Redirect statement just after the point where EmailClient.Send is called. For example if you have some MessageSent.aspx page then you can adjust your code as below

Code: Select all

try
{
MessageLabel.Text = "Message Sent";
MessageLabel.CssClass = "goodCondition";
EmailClient.Send(mailMessage);
Response.Redirect("~/MessageSent.aspx");
[Add this]
Email.text="";
Name.text="";
Comment.text="";
}

Re: ContactUs Control

Posted: Sun Jan 04, 2009 1:44 pm
by Tomgard
Mahzar -
I have created a MessageSent.aspx page but I am not 100% on the modification that needs to be done to ContactUs.ascx.cs in order to create the redirect to this page upon a message submit. Can you clarify this? I am using your ExtendedContactUs code that includes the attachement as seen below -

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Utility;
using System.Text;
using System.Net;
using System.Net.Mail;
using CommerceBuilder.Common;
using CommerceBuilder.Stores;
using System.Net.Mail;
using CommerceBuilder.Messaging;
using System.IO;
public partial class ConLib_ContactUs : System.Web.UI.UserControl
{
    private bool _enableCaptcha = true;

    [Personalizable(), WebBrowsable()]
    public bool EnableCaptcha
    {
        get { return _enableCaptcha; }
        set { _enableCaptcha = value; }
    }

    private string _subject = "New Contact Message";

    [Personalizable(), WebBrowsable()]
    public string Subject
    {
        get { return _subject; }
        set { _subject = value; }
    }

    private string _successMessage = "Thank you for contacting us. Your message has been submitted. If needed, we may contact you at the email address you have provided.";

    private string _failureMessage = "We are experiencing some problems at this time and can not process your request.";

    private string _sendTo;

    [Personalizable(), WebBrowsable()]
    public string SendTo
    {
        get { return _sendTo; }
        set { _sendTo = value; }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        CaptchaPanel.Visible = EnableCaptcha;
    }

    private void RefreshCaptcha()
    {
        CaptchaImage.ChallengeText = StringHelper.RandomNumber(6);
    }

    protected void ChangeImageLink_Click(object sender, EventArgs e)
    {
        RefreshCaptcha();
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        if(EnableCaptcha)
        {
            if (CaptchaImage.Authenticate(CaptchaInput.Text))
            {
                SubmitComment();
                CaptchaInput.Text = "";
                RefreshCaptcha();    
            }
            else
            {
                //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE
                CustomValidator invalidInput = new CustomValidator();
                invalidInput.Text = "*";
                invalidInput.ErrorMessage = "You did not input the verification number correctly.";
                invalidInput.IsValid = false;
                phCaptchaValidators.Controls.Add(invalidInput);
                CaptchaInput.Text = "";
                RefreshCaptcha();    
            }
        }
        else
        if(!EnableCaptcha)
        {
            SubmitComment();
        }
    }

    protected void SubmitComment() 
    {
        Store store = Token.Instance.Store;
        StoreSettingCollection settings = store.Settings;
        MailMessage mailMessage = new MailMessage();

        if (String.IsNullOrEmpty(SendTo))
            mailMessage.To.Add(settings.DefaultEmailAddress);
        else
            mailMessage.To.Add(SendTo);
        mailMessage.From = new System.Net.Mail.MailAddress(Email.Text);
        mailMessage.Subject = Subject;
        mailMessage.Body += "Name: " + FullName.Text + Environment.NewLine;
        mailMessage.Body += "Email: " + Email.Text + Environment.NewLine;
        mailMessage.Body += "Comment: " + Environment.NewLine + Comments.Text;
        mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
        mailMessage.IsBodyHtml = false;
        if(AttachedFile.HasFile)
        {
            HttpPostedFile httpPostedFile = AttachedFile.PostedFile;
            int attachedFileLength = httpPostedFile.ContentLength;
            if (attachedFileLength > 0)
            {
                string attachedFileName = Path.GetFileName(httpPostedFile.FileName);
                httpPostedFile.SaveAs(Server.MapPath("~/Assets/"+attachedFileName));
                Attachment attachment = new Attachment(Server.MapPath("~/Assets/" + attachedFileName));
                mailMessage.Attachments.Add(attachment);
             }
        }
        mailMessage.Priority = System.Net.Mail.MailPriority.High;
        SmtpSettings smtpSettings = SmtpSettings.DefaultSettings;

        try
        {
            EmailClient.Send(mailMessage);
            MessageLabel.Text = _successMessage;
            MessageLabel.ForeColor = System.Drawing.Color.Green;
        }
        catch (Exception exp)
        {
            Logger.Error("ContactUs Control Exception: Exp" + Environment.NewLine + exp.Message);
            MessageLabel.Text = _failureMessage;
            MessageLabel.ForeColor = System.Drawing.Color.Red; 
        }
    }

    private string GetMessage()
    {
        StringBuilder body = new StringBuilder();
        body.Append("Full Name:- " + FullName.Text + Environment.NewLine);
        body.Append("Email:- " + Email.Text + Environment.NewLine);
        body.Append("Comments:- " + Environment.NewLine);
        body.Append(Comments.Text + Environment.NewLine);
        return body.ToString();
    }
}


Re: ContactUs Control

Posted: Mon Jan 05, 2009 6:05 am
by mazhar
Locate following code

Code: Select all

try
        {
            EmailClient.Send(mailMessage);
            MessageLabel.Text = _successMessage;
            MessageLabel.ForeColor = System.Drawing.Color.Green;
        }
and make it look like

Code: Select all

try
        {
            EmailClient.Send(mailMessage);
            MessageLabel.Text = _successMessage;
            MessageLabel.ForeColor = System.Drawing.Color.Green;
            Response.Redirect("~/MessageSent.aspx");
        }

Re: ContactUs Control

Posted: Mon Jan 05, 2009 9:31 am
by Tomgard
Works perfect - thanks!

Re: ContactUs Control

Posted: Tue Jan 13, 2009 4:41 pm
by Tomgard
Since I have been using this control I have been getting some errors logged in my view error log. The message says 'ContactUs Control Exception: EXP Thread was being aborted.' and the Debug Data section is blank. Any ideas what may cause this and why I am getting it?