note 57715 deleted from ref.mail by didou
| From: | didou@php.net | Date: | Sun, 23 Apr 2006 22:33:26 +0000 |
| Subject: | note 57715 deleted from ref.mail by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109206@lists.php.net to get a copy of this message | ||
Note Submitter: Pete Wake
----
I too have had someone trying to use my site to send spam email by injecting headers and using a
bcc: address. One way to stop this is by creating a multipart message as shown in the code below.
Note that to pass the 'antispam' checks of hotmail etc. you should set up
automailer@mysite.com as a "real" email account, so that if anyone checks it'll
actually be there.
<?php
// YOU CAN SET THESE ALL UP YOURSELF
DEFINE("NAME","MySite");
DEFINE("RETURN_ADDRESS","automailer@mysite.com");
$contactemail="personToContact@their-email.com";
$contactname="Person to Contact";
$subject="The subject";
$messageNotHTML="This is the message in text format";
// THE MAIN FUNCTIONALITY
$boundary = md5(time().rand(1,100));
$headers = "MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=\\"{$boundary}\\"
X-Mailer: PHPmailer
From: \\"".NAME."\\" <".RETURN_ADDRESS.">
";
$message = "
--{$boundary}
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
$messageNotHTML
--{$boundary}--
";
$didmail = mail("\\"".$contactname."\\"
<".$contactemail.">", $subject, $message, $headers);
?>