PDA

View Full Version : Evite Script to Send HTML Email



sosADAMsos
January 29th, 2009, 01:11 PM
I would like to have a form on my website where a user can enter their friends email address and name, then click send, and it would send an html email to the friend (an evite).

Is there a script or anything out there for this? I've looked but can't find much. My php is a little limited.

I've been using this script, but it sends emails in plain text. Is there a way to cahnge it to html?


<?php

// ************Begin Configure***************

//Put your website name between the quotes below:
$websiteName = "My Website";

//Put your website address between the quotes below:
$websiteAddress = "www.domain.org/evite.html";


// If you have a privacy policy, put in the link title:
$privacyPolicyLinkText = "";


// Put in the "" the url to you your privacy policy, if you have one,
$privacyPolicyLinkURL = "";


// Change the 0 to a 1 below,
//if you want to recieve a notice when people are refered:
$notice = 1;


//Put your email address in the " " if you changed the notice to 1
$adminEmail = "test@domain.com";


//Put the subject line text you want the email to read in the "":
$subject = "You have been invited to...";

// Put your default message intro text in the first set of quotes below
//This is what the people who are referred will see
//along with any personal message entered by the referer.
$defaultMessageIntro = "<div style="background:#555555;">Join me at...!</div> " . "\n" ;


//Put in the "" your default close (this will be at the end of the message):
$defaultMessageClose = "__________________________________________________ __________________

CUSTOM MESSAGE GOES HERE";


// ************End Configure****************

// Set the link that will be in intro/invite and used to send the referer back
if (isset($_POST['link'])) {
$link = $_POST['link'];
}
else {
if (empty($_SERVER['HTTP_REFERER'])) {
$link = 'http://' . $websiteAddress;
} else {
$link = $_SERVER['HTTP_REFERER'];

}
}
// Add the link to the intro
$defaultMessageIntro = $defaultMessageIntro . $link . "\n";

//Adds a space infront of the subject line (to add a name latter
$subject = ' ' . $subject;
?>
<?php
function doTellForm ($privacyPolicyLinkText, $privacyPolicyLinkURL, $defaultMessageIntro, $link)
{
// HTML
$theForm = <<<EOD
<form name="tellForm" method="post" action="">
<table width="410" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="50%"><div align="center">Your name:</div></td>
<td width="50%"><div align="center">Your email:</div></td>
</tr>
<tr>
<td> <div align="center">
<input name="your_name" type="text" id="your_name">
</div></td>
<td> <div align="center">
<input name="your_email" type="text" id="your_email">
</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center">Name(s) of your friend(s):</div></td>
<td><div align="center">Email(s) of your friend(s):</div></td>
</tr>
<tr>
<td> <div align="center">
<input name="friend_name1" type="text" id="friend_name1">
</div></td>
<td width="50%"> <div align="center">
<input name="friend_email1" type="text" id="friend_email1">
</div></td>
</tr>
<tr>
<td> <div align="center">
<input name="friend_name2" type="text" id="friend_name2">
</div></td>
<td> <div align="center">
<input name="friend_email2" type="text" id="friend_email2">
</div></td>
</tr>
<tr>
<td> <div align="center">
<input name="friend_name3" type="text" id="friend_name3">
</div></td>
<td> <div align="center">
<input name="friend_email3" type="text" id="friend_email3">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<p>Your Message (optional):
<input name="tellsubmit" type="hidden" id="tellsubmit4" value="doTheSend">
<input name="link" type="hidden" id="link" value="$link">
<br>
<textarea name="message" rows="5" id="textarea" style="width:400px;">$defaultMessageIntro</textarea>
</p>
</div></td>
</tr>
<tr>
<td colspan="2"><p align="center">
<input type="submit" name="Submit" value="Send It!">
</p></td>
</tr>
</table>
<div align="center">
</div>
</form>
EOD;
echo ($theForm);
}
?>
<?php

function spamcheck($array) {
# returns true if data is ok, otherwise false if it is spam-looking
return (!preg_match("/(MIME-Version:|Content-Type:|\n|\r)/i", join('',array_values($array)) ));
}


function myMailFunction($mailto, $subject, $message, $headers, $defaultMessageClose, $adminEmail, $notice) {
$message = $message . "\n\n" . $defaultMessageClose;

// Check for suspected spam content
if (!spamcheck(array($mailto,$subject,$headers))) {
die('no spam please');
}

if (@mail($mailto, $subject, $message, $headers)) {
echo ('<p>Your message was successfully sent to ' . $mailto . '</p>');
if ($notice == 1) {
$message = "From email " . $headers . "\n\n" . "To email " . "\n\n" . $mailto . "\n\n" . $message;
@mail($adminEmail, "Evite Was Sent", $message);
}
}
else {
// error message if the email did not send.
echo('<p>Mail could not be sent to ' . $mailto . ' Please use your back button to try them again.</p>');
}
}
?>
<?php

function doTell ($notice, $adminEmail, $subject, $websiteName, $defaultMessageClose, $link) {
if ($_POST['your_email'] != "") {
$headers = 'From: ' . $_POST['your_name'] . '<' . $_POST['your_email'] . '>';
}
else {
$headers = 'From: ' . $websiteName . '<' . $adminEmail . '>';
}


if ($_POST['friend_email1'] != "") {

$mailto1 = $_POST['friend_email1'];

//This tacs the name onto the subject line
$subject1 = $_POST['friend_name1'] . $subject;
//This tacs the name onto the message
$message1 = $_POST['friend_name1'] . "\r\n" . $_POST['message'];


myMailFunction($mailto1, $subject1, $message1, $headers, $defaultMessageClose, $adminEmail, $notice);
}

if ($_POST['friend_email2'] != "") {

$mailto2 = $_POST['friend_email2'];

//This tacs the name onto the subject line
$subject2 = $_POST['friend_name2'] . $subject;
//This tacs the name onto the message
$message2 = $_POST['friend_name2'] . "\r\n" . $_POST['message'];

myMailFunction($mailto2, $subject2, $message2, $headers, $defaultMessageClose, $adminEmail, $notice);
}
if ($_POST['friend_email3'] != "") {

$mailto3 = $_POST['friend_email3'];

//This tacs the name onto the subject line
$subject3 = $_POST['friend_name3'] . $subject;
//This tacs the name onto the message
$message3 = $_POST['friend_name3'] . "\r\n" . $_POST['message'];

myMailFunction($mailto3, $subject3, $message3, $headers, $defaultMessageClose, $adminEmail, $notice);
}

$return = <<<EOD
<p align="center"><a href="$link">Go back to SCG Easter</a></p>
EOD;

echo ($return);
}
?>
<?php

if (isset($_POST['tellsubmit'])) {
doTell($notice, $adminEmail, $subject, $websiteName, $defaultMessageClose, $link);
}
else {
doTellForm($privacyPolicyLinkText, $privacyPolicyLinkURL, $defaultMessageIntro, $link);
}
?>

yungwunn911
April 5th, 2009, 10:30 PM
bump can anyone help with this? I too want to be able to format my incoming e-mails. I am using this as php code.

<?php

$sendTo = "mikesaba@gmail.com";
$subject = "Caram Mens Inquiry";


$headers = "From: " . $_POST["Name2"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];

$message = $_POST["message"];
$message .= $_POST["name2"];
$message .= $_POST["email"];
$message .= $_POST["subject"];


mail($sendTo, $subject, $message, $headers);

?>

when e-mails come in, all data appears on a single line, with no spaces. I would like to add line breaks.

NeoDreamer
April 12th, 2009, 12:47 AM
Your headers should be:



$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


Then you can use <br /> and other HTML tags in your email.