Skip to content

Instantly share code, notes, and snippets.

@ateddy42
Last active August 29, 2015 14:18
Show Gist options
  • Save ateddy42/0624a36ed07e262f177f to your computer and use it in GitHub Desktop.
Save ateddy42/0624a36ed07e262f177f to your computer and use it in GitHub Desktop.
Simple php file to send emails to any address 'from' any address using the PHP mail() function. For use only with your own email address, or with emails ending with "@example.com".
<?php
if ( count( $_GET ) > 0 )
HandleCommand( $_GET );
else
HandleCommand( $_POST );
function HandleCommand( $vars ) {
$command = $vars["command"];
switch ( $command ) {
case NULL:
case "":
case "email":
Email( $vars );
break;
case "send":
Send( $vars );
break;
default:
echo "Unrecognized command: $command";
break;
}
}
function Email( $vars ) {
echo <<<END
<html>
<head>
<meta name="viewport" content="width=300" />
<meta name="format-detection" content="telephone=no" />\n
</head><body>
<form id='email' method='post' action='email.php'>
To Email: <input id="to" name="to" onkeypress='return noenter()'><br/>
From Email: <input id="from" name="from" onkeypress='return noenter()'><br/>
From Name: <input id="fromname" name="fromname" onkeypress='return noenter()'><br/>
Subject: <input id="subject" name="subject" onkeypress='return noenter()'><br/><br/>
Message:<br/><textarea name="message" style='margin:5px 0;width:280;padding:3px;height:75'></textarea><br/>
Image URL: <input id="image" name="image" onkeypress='return noenter()'><br/>
<button name="command" value="send">Send Email</button>
</form>
</body>
</html>
END;
}
function Send( $vars ) {
$to = $vars['to'];
$from = $vars['from'];
$fromName = $vars['fromname'];
$subject = $vars['subject'];
$msg = $vars['message'];
$image = $vars['image'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= 'From: ' . $fromName . ' <' . $from . '>' . "\r\n";
$headers .= 'Reply-To: ' . $fromName . ' <' . $from . '>' . "\r\n";
if ($image != '')
$msg2 = "<html><body><img src='" . $image . "' alt='' />" . $msg . "</body></html>";
else
$msg2 = "<html><body>" . $msg . "</body></html>";
mail( $to, $subject, $msg2, $headers, "-f$from");
echo <<<END
<html>
<head>
<meta name="viewport" content="width=300" />
<meta name="format-detection" content="telephone=no" />\n
</head><body>
<form id="email" method="post" action="email.php">
Invite has been sent.<br/><br/>
<button value="email" name="command">Send Another</button>
</form>
</body>
</html>
END;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment