Wednesday, November 18, 2009

Share Image (Email) to your friend using Bcc email address in php

Send Image as news letter or share image to all ur friend of the site in php though email using BCC address.

This image form and take user email id and verify that email id using java script code. u can send mail to more then one friend. u can save reciver id in your database

Image Form File

<style type="text/css">

#emailtext{
font-family:Verdana;
font-size:14px;
color:#282828;

}

.txtBox {
border:#333333 solid 1px;
}
.imgBox {
border:#FF9900 solid 1px;
}
</style>

<script language="javascript">


function checkFieldEmpty(textField,mess){

var textFieldValue=textField.value;

if(textField=="" || textFieldValue.length==0){// && textField=" "){

alert(mess)

return false;

}else{

//return true;

return "";
}

}


// Javascript Email Verification function

function chkEmail(elem, errorshow){

var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){

return "";
}else{
alert(errorshow);

return false;
}
}

function FormSubmit(theForm){

//alert("in submit");

var reason="";



reason += checkFieldEmpty(document.getElementById('senderName'),'Enter Your Name');
reason += checkFieldEmpty(document.getElementById('senderEmail'),'Enter Your Email');
reason += checkFieldEmpty(document.getElementById('recEmail'),'Enter Email To send');
reason += chkEmail(document.getElementById('senderEmail'),'Enter Your Email correct');
//reason += chkEmail(document.getElementById('recEmail'),'Enter Send To Email correct');


if(reason!=""){
alert("Some Field Need To Fill");
}else{
theForm.submit();
}
}



</script>

<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td align="center" class="imgBox"><img src="<?php echo getPath($Id,$dbc); ?> " height="600" width="700"></td>
</tr>
<tr>
<td>
<form action="sendShareImage.php" method="post" name="shareForm">
<table width="400" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td><span id="emailtext">Your Name</span></td>
</tr>
<tr>
<td><input type="text" name="senderName" id="senderName" size="50" class="txtBox"><input type="hidden" name="id" value="<?php echo $Id;?>"></td>
</tr>
<tr>
<td><span id="emailtext">Your E-mail address</span></td>
</tr>
<tr>

<td><input type="text" name="senderEmail" id="senderEmail" size="50" class="txtBox"></td>
</tr>
<tr>
<td><span id="emailtext">Your Message:-</span></td>
</tr>
<tr>

<td><textarea name="sendermsg" id="sendermsg" cols="50" rows="5" ></textarea></td>
</tr>

<tr>
<td><span id="emailtext">Recipient E-mail address</span></td>
</tr>
<tr>

<td>
<input type="text" name="recEmail" id="recEmail" size="50" class="txtBox"><br />

(use , for multiple emailId)</td>
</tr>
<tr>

<td><strong>Bcc.</strong><br /><input type="text" name="bccsenderEmail" id="bccsenderEmail" size="50" class="txtBox"></td>
</tr>
<tr>
<tr>
<td>&nbsp;</td>
<td align="right" valign="bottom"><img src="images/send.gif" onClick="FormSubmit(shareForm)" />&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</form>

</td>
</tr>
</table>

//End of file of image form

File of mail send start

<style type="text/css">

#send{
display:block;
background-color:#00CC66;
color:#FFFFFF;
text-align:center;
}
#fail{
display:block;
background-color:#FF3300;
color:#FFFFFF;
text-align:center;
}
#tbc{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
color:#000060;
}
</style>

<?php

$dbc=mysql_connect('localhost','root','');
mysql_select_db(db_name,$dbc);

set_time_limit(0);

$Id=$_REQUEST['id'];

$senderName=$_REQUEST['senderName'];
$sender=$_REQUEST['senderEmail'];
$receiver=$_REQUEST['recEmail'];
$senderMsg=$_REQUEST['sendermsg'];
$bccid=$_REQUEST['bccsenderEmail'];

//**********************Function to get Image Path*******************

function getPath($imgId,$dbc){

$selPath="select path,id from wallpaper where id=$imgId";
$Result=mysql_query($selPath,$dbc) or die('Error in fetch Thum Image:-'.mysql_error());
$row=mysql_fetch_array($Result);
return($row[0]);

}

//**********************End of Image Path Function********************

$sub="Image Sharing";

$headers = "From: $sender\r\n";

$headers .= "Content-type: text/html\r\n";
$headers .= "Bcc:$bccid"; //Send any bcc address

$imgPath = getPath($Id,$dbc);

$imgPath = str_replace( ' ', '%20', $imgPath );
//echo $imgPath;

$bodyTxt;

$bodyTxt='

<html>

<body>

<p>Dear friend of '.$senderName.',</p>

<img src="http://www.servername.com/wallpaper/'.$imgPath.'" height="800" width="1000"><br>

<p>
'.$senderMsg.'
</p>


<p>Thank you!</p>

</body>

</html>';

if(mail($receiver,$sub,$bodyTxt,$headers)){



$maxId="select max(id) from shareimg";
$res=mysql_query($maxId,$dbc);
$rs=mysql_fetch_row($res);
$shreId=$rs[0];
$newId=$shreId+1;
//echo $newId;
$saveId="insert into shareimg values($newId,'$senderName','$sender','$receiver','y')";
if(mysql_query($saveId,$dbc)){
echo'<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" height="81"><img src="images/successfulHeader.png" width="100%"></td>

</tr>
<tr>
<td colspan="2" valign="top"><span id="success">&nbsp;&nbsp;Successful !</span><br>
<span id="invitetbc">&nbsp;&nbsp;&nbsp;&nbsp;Your Wallpaper has been Sent</span></td>

</tr>
<tr>
<td width="158" height="185" align="left">&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.getPath($Id,$dbc).'" width="140" /></td>
<td width="342" align="left" valign="middle"><span id="senderName">'.$senderName.'</span><br />
<span id="invitetbc">Your Desktop Wallpaper has been Sent to</span><br /><span id="tbc">'. $receiver.'</span></td>
</tr>
<tr>
<td colspan="2"><i><span id="invitetbc">&nbsp;&nbsp;&nbsp;&nbsp;We Invite you to:</span></i></td>

</tr>
<tr>
<td valign="middle" align="center">&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/sideimage.jpg" /></td>
<td>
<span id="tbc">

</span>


</td>
</tr>
</table>';

}

}else{
echo '<span id="send">Sending Fail</div>';
}

?>

No comments:

Post a Comment