Link to home
Start Free TrialLog in
Avatar of censura
censura

asked on

set up of web form for my wifes 40th web site

Hi - I have a web form with the following:-
<input type="hidden" name="owner_email" id="owner_email" value="test@gmail.com" />
                                <input type="hidden" name="serverProcessorType" id="serverProcessorType" value="php" />
                                <input type="hidden" name="smtpMailServer" id="smtpMailServer" value="localhost" />
                                <input type="hidden" name="stripHTML" id="stripHTML" value="true" />
                               
and am trying to set this up to work with my hmailserver. I have purchased a domain birthday40.co.uk and added this to the list of domains on the hmailserver , added a email test@birthday40.co.uk and tried to email to this and got an error domain not found (which maybe because it is only a few hrs ago since i registered it ) but windered oif i need to do anything else. Also with the above html code what do i need to add i am using gmail.com as a email account at the momment

Hope some one can shed some light on these 2 issues

Avatar of nedlogan
nedlogan
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,
Not sure I understand your question but I'll try to answer. You can't send results of the form directly to the mail server and on to the email address, the website will need to process them in some way then access the mail server (localhost, port 25) to send the results to the email address.

Also the domain you say has been registered shows the following:
"No match for "birthday40.co.uk".
This domain name has not been registered.
WHOIS lookup made at 20:29:57 02-Mar-2011"

They should be browsable within an hour or so.

Finally once you are sure the domain is registered you will need to update the nameservers so email is delivered to your hmail server.

Regards.
Avatar of censura
censura

ASKER

OK thank you the mail handerling script is the following -

?<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Net.Mail;
using System.Text.RegularExpressions;

public class Handler : IHttpHandler {
      public void ProcessRequest (HttpContext context) {
            SmtpClient mailClient = new SmtpClient(context.Request.Form.Get("smtpMailServer"));
            string owner_email = context.Request.Form.Get("owner_email");
            string subject = "A message from your site visitor " + context.Request.Form.Get("name");
            string email = context.Request.Form.Get("email");
            string messageBody = "";
      
            messageBody += "<p>Visitor: " + context.Request.Form.Get("name") + "</p>\n";
            messageBody += "<br>\n";
            messageBody += "<p>Email Address: " + context.Request.Form.Get("email") + "</p>\n";
            messageBody += "<br>\n";
            messageBody += "<p>Phone Number: " + context.Request.Form.Get("phone") + "</p>\n";
            messageBody += "<br>\n";
            messageBody += "<p>Message: " + context.Request.Form.Get("message") + "</p>\n";
      
                  
            MailMessage message = new MailMessage();
      
            try{
                  message.From = new MailAddress(email.ToString());
            }catch (FormatException e) {
                  context.Response.Write(e.Message);
            }
      
            message.To.Add(owner_email);
            message.Subject = subject;
            if(context.Request.Form.Get("stripHTML") == "true"){
                  message.IsBodyHtml = false;
            messageBody = Regex.Replace(messageBody, "<.*?>", string.Empty);
            }else{
                    message.IsBodyHtml = true;
            }
            message.Body = messageBody;
            
            try{
                  mailClient.Send(message);
            }catch (SmtpException e) {
                  context.Response.Write("mail failed");
            }
            context.Response.Write("mail sent");
      }

      public bool IsReusable {
            get      {
                  return false;
            }
      }
}

I am using hmailserver and have a vps where it resides - what inputs do i need

the code for the email form is

<input type="hidden" name="owner_email" id="owner_email" value="test@shamim40.co.uk" />
                                <input type="hidden" name="serverProcessorType" id="serverProcessorType" value="php" />
                                <input type="hidden" name="smtpMailServer" id="smtpMailServer" value="localhost" />
                                <input type="hidden" name="stripHTML" id="stripHTML" value="true" />
                               
I have put as you can see test@shamim40.co.uk as the owner eamil which is the email i have added to the hmailserver do i add hmailserver to id smtpmailserver and what about server processing type.

Currently o have the hmailserver pointing to a gmail account for delivery is this ok

hope you can help
Hi,
Ideally you should post your form when submitting and store smtp details in your web.config file so others cannot access them by viewing the source of your pages.

Within the form handling you can specify an email to send the results to. The results should be able to be sent to most email addresses. I'm not familiar with hmailserver specifically but you should be able to send email through it by specifying address: localhost or vps ip, port: usually 25, username and password, often the email address and password of an existing pop3 account on the server.

If you have the following form:

Name: <asp:TextBox ID="PersonName" runat="server"></asp:TextBox><br />
Email: <asp:TextBox ID="PersonEmail" runat="server"></asp:TextBox><br />
Message: <asp:TextBox ID="PersonMessage" runat="server"></asp:TextBox><br />
<asp:Button ID="Submit" runat="server" Text="Submit" OnClick="Submit_Click" />

And this on your code behind page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net.Mail;

public partial class xp : System.Web.UI.Page//xp is the page name I used
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Submit_Click(object sender, EventArgs e)
    {

        SmtpClient sc = new SmtpClient();
        StringBuilder sb = new StringBuilder();
        MailMessage msg = null;

        sb.Append("Hello from: " + PersonName.Text + "\n");
        sb.Append("Email: " + PersonEmail.Text + "\n");
        sb.Append("Message: " + PersonMessage.Text + "\n");
        msg = new MailMessage(PersonEmail.Text, "me@myemail.co.uk", "Hello from your website", sb.ToString());//from, to, subject, body
        sc.Send(msg);
        msg.Dispose();
    }

}

Open in new window


Then put the following in your web.config (inside the <configuration> </configuration> tags):
<system.net>
		<mailSettings>
			<smtp from="">
				<network host="localhost" port="25" password="yourpassword" userName="yourusername"/>
			</smtp>
		</mailSettings>
	</system.net>

Open in new window


You should be on your way to getting it working as you wish. You can further customise the form and what is displayed to your visitors, but this is the basics.

Hope it helps.

Regards.
Avatar of censura

ASKER

Hi i have the following now set up with hosting company and email service which i have tested and now works ok, using microsoft out look. So for my form to work i am still not clear what to use as inputs - as mentioned here is the form code from what i can see i need 3 inputs

1)value for owner email which i presume is where to send form info ie test@shamim40.co.uk as i have put.

2)Service processor type which i dont know what to put here is it pop

3)smtpMail serverid - which says local host but i am using the host companies mail server for incoming and outgoing mail which is mail.shamim40.co.uk or the mailserver name is
Nameserver 1: ns101.bbvpsdns.com (209.222.13.205)


<input type="hidden" name="owner_email" id="owner_email" value="test@shamim40.co.uk" />
                                <input type="hidden" name="serverProcessorType" id="serverProcessorType" value="php" />
                                <input type="hidden" name="smtpMailServer" id="smtpMailServer" value="localhost" />
                                <input type="hidden" name="stripHTML" id="stripHTML" value="true" />

Thank you
               
ASKER CERTIFIED SOLUTION
Avatar of nedlogan
nedlogan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of censura

ASKER

still not working