Mon Jun 15 2020

Send E-mail

PHP Scripting1081 views

File Name: send-email.php

<html>
	<head>
		<title>Send Mail</title>
	</head>
	<body>
		<?php
			if(isset($_POST['mail_to'])) {

				/* Send from */
				$from_add = "info@geekboots.com";
				
				/* Email headers */
				
				/* Email contain type and version */
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
				
				/* Email send from and subject */
				$headers .= 'From: Geekboots <'.$from_add.'>' . "\r\n";
				$headers .= "Subject: ".$_POST['subject']."\r\n";
				
				/* Reply path of the mail */
				$headers .= "Reply-To: ".$from_add."\r\n";
				$headers .= "Return-Path: ".$from_add."\r\n";
				
				/* Organisation of the mail sender */
				$headers .= "Organization: Geekboots\r\n";
				
				/* Unique message id */
				$headers .= "Message-ID: <notif-".time()."@geekboots.com>\r\n";
				
				/* Mailer info */
				$headers .= "X-Mailer: Geekboots, PHP v".phpversion()."\r\n";
				
				/* PHP mail() function to send mail */
				if(mail($_POST['mail_to'], $_POST['subject'], $_POST['message'], $headers))
					echo "Mail sent successfully!";
				else
					echo "Send fail!";
				
			}
		?>
		<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="email" name="mail_to" required placeholder="To" /><br />
			<input type="text" name="subject" required placeholder="Subject" /><br />
			<textarea name="message" placeholder="Message"></textarea><br />
			<input type="submit" value="Send" />
		</form>
	</body>
</html>



/* Output */
To: yourmail@gmail.com
Subject: Testing
Message: Testing PHP Mail

Mail sent successfully!
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.