Last active
October 23, 2015 10:18
-
-
Save amityweb/a4e016a4ed3e7d75e43b to your computer and use it in GitHub Desktop.
Simple script to test sending an email to an email address using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* DO NOT LEAVE THIS LIVE ON A SERVER */ | |
$sendemail = true; // Simple switch to enable or disable sending to be safe | |
if (isset($_POST['email']) && $sendemail) | |
{ | |
$to = $_POST['email']; | |
$from = $_POST['email_from']; | |
$subject = $_POST['subject']; | |
$message = $_POST['message']; | |
$headers = array(); | |
$headers[] = "MIME-Version: 1.0"; | |
$headers[] = "Content-type: text/plain; charset=iso-8859-1"; | |
$headers[] = "From: ".$from." <".$from.">"; | |
$headers[] = "Reply-To: Recipient Name <".$to.">"; | |
$headers[] = "X-Mailer: PHP/".phpversion(); | |
if (mail($to, $subject, $message, implode("\r\n", $headers))) | |
{ | |
echo '<span style="color: green;">Email Sent</span>'; | |
} | |
else | |
{ | |
echo '<span style="color: red;">Problem sending email</span>'; | |
} | |
} | |
if (!$sendemail) | |
{ | |
echo '<span style="color: red;">Send mail disabled</span>'; | |
} | |
else | |
{ | |
?> | |
<br/><br/> | |
<form method="post"> | |
Send Email To: <input name="email" type="text" /><br /><br/> | |
Send Email From: <input name="email_from" type="text" value="[email protected]"/><br /><br/> | |
Subject: <input name="subject" type="text" value="Test subject <?php echo date('d-m-y h:i');?>"/><br /><br/> | |
Message:<br /><br/> | |
<textarea name="message" rows="15" cols="40">Test email message</textarea><br /><br/> | |
<input type="submit" value="Submit" /> | |
</form> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment