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..:
1) to send invites
2) From address to be of the user
3) 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."' . "\r\n" .
'Reply-To: ".$from."' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'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
/*
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
*/
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("\t","",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>\n";
$headers.= "Reply-To: \"$fromname\" <$from>\n";
// 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.= "\t"; }
$headers.= "\"".$ccname[$i]."\" <".$cc[$i].">\n";
}
} else {
$headers.= "Cc: \"$ccname\" <$cc>\n";
}
}
// 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.= "\t"; }
$headers.= $bcc[$i]."\n";
}
}
} else {
$headers.= "Bcc: \"$bccname\" <$bcc>\n";
}
}
// Construct the message
$headers.= "MIME-Version: 1.0\n";
if ($attachments){
$headers.= "Content-Type:
multipart/mixed;\n\tboundary=\"----=_NextPart_000_THE_1ST_B0UNDARY\"\n";
} else {
$headers.= "Content-Type:
multipart/alternative;\n\tboundary=\"----=_NextPart_000_THE_1ST_B0UNDARY\"\n";
}
$headers.= "X-Priority: $priority\n";
$headers.= "X-Mailer: 1 2 Mime Mail v0.3\n";
$headers.= "\n";
$headers.= "This is a multi-part message in MIME format.\n";
$headers.= "\n";
$headers.= "------=_NextPart_000_THE_1ST_B0UNDARY\n";
if ($attachments){
$headers.= "Content-Type:
multipart/alternative;\n\tboundary=\"----=_NextPart_001_THE_2ND_B0UNDARY\"\n";
$headers.= "\n";
$headers.= "------=_NextPart_001_THE_2ND_B0UNDARY\n";
}
$headers.= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$headers.= "Content-Transfer-Encoding: quoted-printable\n";
$headers.= "\n";
$headers.= wordwrap($text,76)."\n";
if ($attachments){
$headers.= "------=_NextPart_001_THE_2ND_B0UNDARY\n";
} else {
$headers.= "------=_NextPart_000_THE_1ST_B0UNDARY\n";
}
$headers.= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$headers.= "Content-Transfer-Encoding: base64\n\n";
$headers.= "\n";
$headers.= chunk_split(base64_encode($html))."\n";
$headers.= "\n";
// Attach the attachments to this mail
if($attachments){
$headers.= "------=_NextPart_001_THE_2ND_B0UNDARY--\n";
$headers.= "\n";
$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\n";
$headers.= "Content-Type:
application/octetstream;\n\tname=\"$atmname\"\n";
$headers.= "Content-Transfer-Encoding: base64\n";
$headers.= "Content-Disposition:
attachment;\n\tfilename=\"$atmname\"\n";
$headers.= "\n";
$headers.=
chunk_split(base64_encode($atmcontent))."\n";
}
}
}
// End of the message
$headers.= "------=_NextPart_000_THE_1ST_B0UNDARY--\n";
// Actually send the mail
if (mail($to,$subject,"",$headers)) {
return true;
} else {
return false;
}
}
?>
Thanking you all in advance
Regards,
SRIRAM