Solved

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

Posted on 2011-03-02
6
594 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:censura
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:nedlogan
ID: 35021490
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.
0
 

Author Comment

by:censura
ID: 35026021
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
0
 
LVL 2

Expert Comment

by:nedlogan
ID: 35026396
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.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:censura
ID: 35036386
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
               
0
 
LVL 2

Accepted Solution

by:
nedlogan earned 500 total points
ID: 35037830
Hi,
Please see my previous answer this contains all info required to answer your question.

To reiterate, DO NOT put the email you are sending to or server name in your form as hidden fields. Anyone viewing the source of your page can see this information. You should keep this info in your code behind page or better still in your web.config file. I'm assuming your creating an ASP.NET website as the code you posted to process your form was in C#

I'm not sure where you are getting these:

"<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" />"

form fields from but they're not required for making your form work.

Your mail server name is: mail.shamim40.co.uk then for username: test@shamim40.co.uk then password should be the password you use with that email address.

Regards.
0
 

Author Comment

by:censura
ID: 35323033
still not working
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now