Hi Friends,
I’m Sriram from India & a learner in PHP.
I brought Email address Importer from a company and when i brought it,
they gave a sample form as below, but its not so professional…
And i wanted few more functions like the mail should be sent in the name of the sender. So i
searched the net and got another form which is also enclosed.
Actually what i want is…:
- to send invites
- From address to be of the user
- and if possible to add all the emails to which invites are sent to my Newsletter software
(send studio) (optional)
But as i donno much of PHP… i’m not able to integrate it into it and get it to work.
Please can any one help…?
Below is the code given while i purchased…
<html>
<head>
<title>Send Mail Test</title>
<style><!--
BODY {font: normal 11px Arial, Verdana, Tahoma;}
.pd {margin-top: 15px; padding: 5px; background-color: #f4f4f4;}
--></style>
</head>
<?
function sendmail($to,$subject,$message){
//set sender's email here
$from="noreply@yourdomain.com";
$headers = 'From: ".$from."' . "
" .
'Reply-To: ".$from."' . "
" .
'X-Mailer: PHP/' . phpversion() . "
" .
'Return-Path: ".$from."' ;
if (mail($to, $subject, $message, $headers)){return true;}else{return false;}
}
//== Set subject and message
$subject=""; //put your subject in PHP Alphanumeric Format e.g. "Hello. This is a test..."
$msgfile="test.php"; //enter the filename which points to your mail content file in html
format e.g. "mailmessage.html"
//========================== do not edit beyond this line
ob_start(); require($msgfile); $message=ob_get_contents(); ob_end_clean();
//== End retrieval
$email = @$_POST['email'];
if(!$email){$email = array();}
foreach ($email as $emailaddress) {
if(@sendmail($emailaddress,$subject,$message)){
echo htmlspecialchars($emailaddress,ENT_QUOTES)."– <b>Mail Sent
Successfully</b><br/>";
}else{
echo htmlspecialchars($emailaddress,ENT_QUOTES)."– <b>Send Mail Failed</b><br/>";
}
}
print "<div class=\"pd\"><b>Total of ".count($email)." selected email addresses
retrieved</b></div>";
?>
Form script i got from Internet
<?php
////////////////////////////////////////////////////////////////////////////////////////////
////////
//////////////////////////
//////////////////////////
////////////////////////// 1 2 SEND MIME MAIL
//////////////////////////
//////////////////////////
//////////////////////////
////////////////////////// (c) 2003 - 2005 Roel Meurders
//////////////////////////
////////////////////////// mail: support [at] roelmeurders [dot] com
//////////////////////////
////////////////////////// version 0.3
//////////////////////////
//////////////////////////
//////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////
/////////////////// For license info look at my website: http://roel.meurders.nl
///////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////
/*
mimemail($mailVars);
$mailVars is the array which holds all or some of the possible variables of the
function
# = Compulsory variable. Function will quit without it
# = variabele, functie geeft terminale fout bij gemis;
+ = Conditional variable, only compulsory if another variable is missing
- = Optional value, function works ok without it.
# $mailVars['to'] = ""; // string / array : If
more than one address, the messages will be send via a http header.
- $mailVars['toname'] = ""; // string / array : If an
array the number of items should equal those of $mailVars['to']
# $mailVars['from'] = ""; // string
: Email address of the sender
- $mailVars['fromname'] = ""; // string :
Name of the sender
- $mailVars['subject'] = ""; // string
: subject of the email
+ $mailVars['text'] = ""; // string
: Message in plain text, only compulsary if both $mailVars['html'] and
// $mailVars['template'] are
not defined.
+ $mailVars['html'] = ""; // string
: Message in html mode, only compulsary if both $mailVars['text'] and
// $mailVars['template'] are
not defined.
+ $mailVars['template'] = ""; // string
: Path to the template file only compulsary if both $mailVars['html'] and
// $mailVars['text'] are not
defined.
- $mailVars['replace'] = "value";// string / array : Search in template
for a string <!--%value%--> and replaces this with
- $mailVars['with'] = ""; // string / array :
the values in this variable
- $mailVars['attachments'] = ""; // string / array :
Attachments, path to the file
- $mailVars['cc'] = ""; // string / array :
Recipients of a CC copy
- $mailVars['ccname'] = ""; // string / array : If an
array the number of items should equal those of $mailVars['cc']
- $mailVars['bcc'] = ""; // string / array :
Recipients of a CC copy.
- $mailVars['priority'] = ""; // anything : If
set priority is high, if not it's normal
NB
- There is no $mailVars['bccname'] because the recipient of bcc mail cannot
see the bcc header anyway.
- If a template file is used. The content of the HTML value will be replaced
by the template
Good luck!
*/
function mimemail($mailVars) {
// Set variables from mailVars.
$vars = array_keys($mailVars);
for ($i=0; $i<count($vars); $i++){
$var = $vars[$i];
$val = $mailVars[$var];
$$var = $val;
}
// Set the priority value;
$priority = $priority ? 1 : 3;
// Get the template if there is one.
if ($template) {
if (file_exists($template)){
$tfd= fopen ($template, "r");
$html = fread($tfd,filesize($template));
fclose ($tfd);
}
}
// Change the html replacements
if ($replace && $with) {
$replace = is_array($replace) ? $replace : array($replace);
$with = is_array($with) ? $with : array($with);
if (count($replace) == count($with)){
for ($i=0;$i<count($replace);$i++){
$html =
str_replace("<!--%".$replace[$i]."%-->",$with[$i],$html);
}
}
}
// Check if there's message content
if ($template){
$text =
trim(html_entity_decode(strip_tags(str_replace(" ","",eregi_replace("(.+)<body([^>]*)>(.*)<
\/body>(.*)","\\3",$html)))));
} else if ($html && !$text) {
$text = html_entity_decode(strip_tags($html));
} else if (!$html && $text) {
$html = nl2br(htmlentities($text));
} else if (!$html && !$text){
return false;
}
// Create recipient, more than one -> to Bcc
if ($to && $from) {
if (is_array($to) && count($to) > 0) {
$bcc = array_merge($to,$bcc);
$toname = $fromname ? $fromname : $from;
$to = $from;
}
$toname = $toname ? $toname : $to;
$to = "\"$toname\" <$to>";
} else {
return false;
}
// Check the subject, if none -> No Subject
$subject = $subject ? $subject : "No Subject";
// Start of header creation
$fromname = $fromname ? $fromname : $from;
$headers = "From: \"$fromname\" <$from>
";
$headers.= "Reply-To: \"$fromname\" <$from>
";
// Create CC headers;
if ($cc) {
$ccname = $ccname ? $ccname : $cc;
if (is_array($cc) && count($cc) > 0){
$headers.= "Cc: ";
for ($i=0;$i<count($cc);$i++) {
if ($i>0) { $headers.= " "; }
$headers.= "\"".$ccname[$i]."\" <".$cc[$i].">
";
}
} else {
$headers.= "Cc: \"$ccname\" <$cc>
";
}
}
// Create BCC headers
if ($bcc) {
if (is_array($bcc) && count($bcc) > 0){
$headers.= "Bcc: ";
for ($i=0;$i<count($bcc);$i++) {
if ($bcc[$i]){
if ($i>0) { $headers.= " "; }
$headers.= $bcc[$i]."
";
}
}
} else {
$headers.= "Bcc: \"$bccname\" <$bcc>
";
}
}
// Construct the message
$headers.= "MIME-Version: 1.0
";
if ($attachments){
$headers.= "Content-Type:
multipart/mixed;
boundary=\"----=_NextPart_000_THE_1ST_B0UNDARY\"
";
} else {
$headers.= "Content-Type:
multipart/alternative;
boundary=\"----=_NextPart_000_THE_1ST_B0UNDARY\"
";
}
$headers.= "X-Priority: $priority
";
$headers.= "X-Mailer: 1 2 Mime Mail v0.3
";
$headers.= "
";
$headers.= "This is a multi-part message in MIME format.
";
$headers.= "
";
$headers.= "------=_NextPart_000_THE_1ST_B0UNDARY
";
if ($attachments){
$headers.= "Content-Type:
multipart/alternative;
boundary=\"----=_NextPart_001_THE_2ND_B0UNDARY\"
";
$headers.= "
";
$headers.= "------=_NextPart_001_THE_2ND_B0UNDARY
";
}
$headers.= "Content-Type: text/plain;
charset=\"iso-8859-1\"
";
$headers.= "Content-Transfer-Encoding: quoted-printable
";
$headers.= "
";
$headers.= wordwrap($text,76)."
";
if ($attachments){
$headers.= "------=_NextPart_001_THE_2ND_B0UNDARY
";
} else {
$headers.= "------=_NextPart_000_THE_1ST_B0UNDARY
";
}
$headers.= "Content-Type: text/html;
charset=\"iso-8859-1\"
";
$headers.= "Content-Transfer-Encoding: base64
";
$headers.= "
";
$headers.= chunk_split(base64_encode($html))."
";
$headers.= "
";
// Attach the attachments to this mail
if($attachments){
$headers.= "------=_NextPart_001_THE_2ND_B0UNDARY--
";
$headers.= "
";
$attachments = is_array($attachments) ? $attachments :
array($attachments);
foreach($attachments as $atm){
if (file_exists($atm)){
$atmname = basename($atm);
$afd= fopen ($atm, "r");
$atmcontent = fread($afd,filesize($atm));
fclose ($afd);
$headers.=
"------=_NextPart_000_THE_1ST_B0UNDARY
";
$headers.= "Content-Type:
application/octetstream;
name=\"$atmname\"
";
$headers.= "Content-Transfer-Encoding: base64
";
$headers.= "Content-Disposition:
attachment;
filename=\"$atmname\"
";
$headers.= "
";
$headers.=
chunk_split(base64_encode($atmcontent))."
";
}
}
}
// End of the message
$headers.= "------=_NextPart_000_THE_1ST_B0UNDARY--
";
// Actually send the mail
if (mail($to,$subject,"",$headers)) {
return true;
} else {
return false;
}
}
?>
Thanking you all in advance
Regards,
SRIRAM