...

View Full Version : Mail Sending



bhav
12-21-2006, 02:38 PM
Hi, i was wondering as i have a importer script how i would make the emails sent to the imported contacts send from the person who imported the emails:

Eg:

someone@hotmail.com imports there contact list

It then sends email to all of their contacts but from someone@hotmail.com

thanks

Tyree
12-21-2006, 02:41 PM
What's your current mail script look like? Or do you not have one yet?

bhav
12-21-2006, 02:43 PM
Well it's the hotmail importer which can be found at www.aur-phala.com/hotmail/

TheLethal
12-21-2006, 02:44 PM
think he meens show the code

bhav
12-21-2006, 02:46 PM
Here's the index.php


<?php
chdir('/home/jaynbhav/public_html/forum');
require_once('/home/jaynbhav/public_html/forum/global.php');
?>

<?

if(intval(@$_POST['update'])==1){

$email=stripslashes(@$_POST['EmailAddress']);

$password=stripslashes(@$_POST['Passwd']);

$output=null;



include("hotmailimporter.php");



$getdata=getdata($email,$password);



if(!$getdata){$output="<b>Failed to import addresses. Please check your username &amp; password.</b>";}else{

$getinfo=getinfo($getdata,1);

$getname=getinfo($getdata,0);

$rt=0; $xgct=0;

while($rt!=count($getinfo)){

if($getinfo[$rt+1]!=null){

$xgct++;

$output.="<tr><td><input type=\"checkbox\" id=\"email[]\" name=\"email[]\" value=\"".htmlspecialchars($getinfo[$rt+1],ENT_QUOTES)."\" checked></td>

<td width=\"200\">".htmlspecialchars($getname[$rt+1],ENT_QUOTES)."</td><td width=\"200\" bgcolor=\"#eeeeee\">".htmlspecialchars($getinfo[$rt+1],ENT_QUOTES)."</td></tr>";

}



$rt++;

}



$checkrow="<tr><td colspan=\"3\" bgcolor=\"#cccccc\"><a onclick=\"select_all(1);\" href=\"javascript: void(0);\"><font color=\"#666666\"><b>Select All</b></font></a> | <a onclick=\"select_all(0);\" href=\"javascript: void(0);\"><font color=\"#666666\"><b>Unselect All</b></font></a></td></tr>";



$output="

<form name=\"formlist\" method=\"POST\" action=\"sendmail.php\">

<table border=\"1\" bordercolor=\"#cccccc\" class=stxt cellspacing=\"6\" cellpadding=\"6\" align=\"center\" style=\"border-collapse: collapse\" width=\"450\">".$checkrow.$output.$checkrow."</table>

<br/><span class=\"stxt\">There are a total of <b>".$xgct."</b> emails being imported.</span><br/><br/><input type=\"submit\" class=\"stxt\" value=\"Send Invitation\"></form>

";



}

}



?>


Here's the sendmail.php:


<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($from="service@livingitlarge.com",$to,$subject,$message){

//set sender's email here

//$from="$sender_name";

$headers = 'From: '.$from.'' . "\r\n" ;

//$headers = 'From: '.$from.'' . "\r\n" .

// 'Reply-To: '.$from.'' . "\r\n" .

// 'X-Mailer: PHP/' . phpversion() . "\r\n" .

// 'Return-Path: '.$from.'' ;

$headers .= "Content-Type: text/html\n";
$headers .= '$email'.$eol;
$headers .= 'Reply-To: $email <$wmail>'.$eol;
$headers .= 'Return-Path: $email <$email>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
if (mail($to, $subject, $message, $headers)){return true;}else{return false;}

}



//== Set subject and message

$subject_header="Newsletter"; //put your subject in PHP Alphanumeric Format e.g. "Hello. This is a test..."



$msgfile="mailmessage.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) {

/*

$i=1;

if($i>=3)exit;

else

{

switch ($i) {

case 0:

$from="invitations@wallop.com";

$subject="Welcome to wallop.com from your friends";

$message = str_replace( '$sender_name', $from,$message);

break;

case 1:

$from="invitations@google.com";

$subject="Welcome to Google.com from your friends";

$message = str_replace( '$sender_name', $from,$message);

break;

case 2:

$from="invitations@dlnow.com";

$subject="An invitation to DLnow.com from your friends";

$message = str_replace( '$sender_name', $from,$message);

break;

}

*/

$from="service@livingitlarge.com";

$subject=$subject_header." ".$from;

$message = str_replace( '$sender_name', $from,$message);



if(@sendmail($from,$emailaddress,$subject,$message)){

echo htmlspecialchars($emailaddress,ENT_QUOTES)."&ndash; <b>Mail Sent Successfully</b><br/>";

}else{

echo htmlspecialchars($emailaddress,ENT_QUOTES)."&ndash; <b>Send Mail Failed</b><br/>";

}

sleep(2);

//$i++;

//}

}



print "<div class=\"pd\"><b>Total of ".count($email)." selected email addresses retrieved</b></div>";

?>

Tyree
12-21-2006, 03:13 PM
First, on your index.php, you're going to need to collect the user's email address and send it to sendmail.php. For this example I'll set it to $userEmail.

Next, change your sendmail() function (I've omitted all the commented line):


function sendmail($from,$to,$subject,$message){

$headers = 'From: '.$from.'' . "\r\n" ;
$headers .='Reply-To: '.$from.'' . "\r\n" ;
$headers .='X-Mailer: PHP/' . phpversion() . "\r\n" ;
$headers .='Return-Path: '.$from.'' . "\r\n" ;
$headers .= "Content-Type: text/html\n" ;
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
if (mail($to, $subject, $message, $headers)){return true;}else{return false;}
}


In sendmail.php...define $from outside of the foreach statment:


$from = $_POST['userEmail'];


Next, change your foreach statement toward the end of the sendmail.php file:


foreach ($email as $emailaddress) {

$subject=$subject_header." ".$from;

$message = str_replace( '$sender_name', $from,$message);

if(@sendmail($from,$emailaddress,$subject,$message)){

echo htmlspecialchars($emailaddress,ENT_QUOTES)."&ndash; <b>Mail Sent Successfully</b><br/>";

}else{

echo htmlspecialchars($emailaddress,ENT_QUOTES)."&ndash; <b>Send Mail Failed</b><br/>";

}

sleep(2);

}


I don't really understand what you're doing with the $message definition there. Where is the text of your message?

So, while I haven't tested this. It should get the $email array, the user's email address and then send an email to each address in the $email array FROM the user's email address.

Hope that helps!

bhav
12-21-2006, 04:14 PM
im still baffled :S

bhav
12-21-2006, 05:34 PM
bump...

nikolas22t
07-11-2007, 02:03 PM
The text of the message is stored in a file- mailmessage.php in our case ...
Also this script is not working now with hotmail , I have it for yahoo and gmail if you need it please contact me to send it.My email address is http://www.tryfonos.net/email.jpg


$msgfile="mailmessage.php"; //enter the filename which points to your mail content file in html format e.g. "mailmessage.html"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum