Dear Experts,

Apparently using the html mailto: action is prone to not working if the users client side email is not properly configured (like hotmail or other web based email apps). Is it possible to catch this error in the html code (via javascript, PHP, or HTML) and take other actions like re-direct to an FORM, so the user does not think the website is broken and goes somewhere else.

John,

You could try something like this:

function sendEmail(address, subject, body){
	//based on http://www.webmasterworld.com/javascript/3290040.htm
	if(!address){ return; }
	var q = [];
	address += (subject||body) ? '?' : '';
	if(subject){ q.push('subject=' + subject); }
	if(body){ q.push('body=' + body); }
	var mailto_link = 'mailto:' + address + q.join('&');
	addMessage(mailto_link);
	try{
		win = window.open(mailto_link,'emailWindow');
		if(win && win.open && !win.closed) win.close();
	}
	catch(e){
		//alternative action
	}
}

The success depends on whether all/any types of email failure generate a javascript error.

I would guess that my code should trap complete failures but not all types of error; eg. hotmail will probably open a browser window inviting user to register, but not give an error.

I tried to stimulate an error by changing browser settings (IE6 under Win 2000) but failed to get one. Maybe this is promising, but does not help in testing the error handling. You may need to get imaginative.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.