Sending email without opening email client

On my linux server, on my PHP page, I have a link when a user clicks on it, it opens an email client with already filled information and hits the “send” button to send an email. The code(which was written by someone) for that is as follows:


<li><b>Email Support Required?</b>: <span class="bg-info">
	<?php
		$newLine = "%0D%0A";
		$supportTeamEmail = "technical_support@mycompany.com";
							
		$sendMailTo = "mailto:" . $supportTeamEmail;
		$mailSubject = "subject="."technical%20Help%20Request" ;
		
		$mailBody = "body=" .  
				"Please%20include%20your%20department%20or%20school%20and%20your%20phone%20number,%20along%20with%20a%20brief%20".
				"description%20of%20the%20data%20you%20need%20or%20the%20problem%20you're%20having%20with%20i2b2."		;			

		$completeEmailLink = "<a href=\"" . $sendMailTo . "?" . $mailSubject . "&" . $mailBody . "\">" . "Click here to email the technical team at MyCompany" . "</a>";
					
	echo $completeEmailLink ;
	?>
	</span></li>
  1. Suppose, I just want to gather the information that the user has filled using an HTML form and send it to a particular email address, is it possible to do so? I mean in this case, the user won’t be seeing all the information in an email client just like above. The email will be sent as soon as user clicks on “Submit” button and a message will be displayed.

  2. Please let me know if there are any SMTP related configuration needed on the server as I am doing it for the first time.

  3. Also, is it a good practice to insert the message in the body of the email just like it’s done above with lots of %20 used for creating space? If not, what’s an efficient way?

  1. Yes. If you have a browse down this forum a few pages you’ll see quite a few discussions about how to send form data by email, so it’s just a case of customising what information you put into the body of the email, and where you send it to. It’ll link to some code on the server (in PHP or some other language) that takes the form data and sends it by email.

  2. I believe there will be a requirement for your server to have access to a configured SMTP server in order to send the email. However, I vaguely recall some talk that using something like PHPMailer instead of the built-in PHP mail() function not only is more reliable, but can also remove that requirement.

  3. As far as I can see, the only requirement for URL-encoding the message string (so replacing spaces with %20, for example) is because it’s being drawn as a URL starting with the mailto: link. Once you’re doing it directly in code and not passing the strings via the URL, there’s no need for that.

2 Likes

@droopsnoot Thanks very much for the answers. I have one more follow-up question:

For #2 ; The way my code is working right now as I mentioned in the post (where a user clicks on the hyperlink and opens an outlook email client with pre-populated information), doesn’t that involve SMTP server configuration to send an email? I mean, I am wondering since that process is already able to send an email, whether SMTP is already configured on my server or not? Thanks

When the user clicks on the “mailto” link, it opens the email client on their computer, not on your server. So the email client will have SMTP configured, but it doesn’t mean that your server does. In fact I think that’s why some sites use “mailto” links - because it means they don’t have to bother with code to send the email, SMTP config, and so on. It also means they can’t be hijacked for doing open relay spam emails.

2 Likes

extending @droopsnoot’s comment: While letting the user write the email with his MTA is quite convenient for you, many users shy away from exposing their email address like that.

2 Likes

Extending both @droopsnoot and @Dormilich posts, SMTP is not what you have in your above code. SMTP is a some what secured way of sending emails and therefore, does not get blocked by spam filters. This is because you have to supply an existing email address with a correct password. Just the slightest typo can give you a 500 error in your SMTP library. Early last year, whois.com has blacklisted all mail() function calls. If you do not supply an existing email and sign it up through whois.com’s email hosting if you have a hosting under them, the email will be rejected without question.

If you want a “working” email sender, I would say to stay away from mail(). This function has been exploited often then usual, hence whois.com blacklisting it senders who use this function.

Going back to my first paragraph, SMTP consists of the outgoing SMTP server, your SMTP email address, your SMTP password, the encrypted type (ssl or tls), and the SMTP port.

1 Like

Thanks very much !

Thanks very much ! @Dormilich

Thanks very much ! @spaceshiptrooper

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.