Jump to content

Why does not it send mail?


Deoctor

Recommended Posts

i have wrote one code which reads the html content line by line and downloads all the images and then make a zip of the folder and sends them to the mail.. I could not able to get Why is this not working. Any help would be greatly appreciated.

 

 

<?php
session_start();
$ses_id = session_id();
session_unset();
session_destroy();
$text = file_get_contents("http://drvirusindia.com"); 
error_reporting(E_STRICT);
preg_match_all("/<img(.*?)src=\"http:\/\/(.*?)\"/",$text, $results,PREG_PATTERN_ORDER);
date_default_timezone_set('America/Toronto');
rrmdir("images/$ses_id");
mkdir("images/$ses_id");
foreach($results[2] as $res){
   // print "Test-->".$res."<br>";
   $remoteImage = "http://".$res;
   save_image($remoteImage,"images/$ses_id/".basename($remoteImage)); 
    if(getimagesize("images/$ses_id/".basename($remoteImage))){
        echo '<h3 style="color: green;">Image ' . basename($remoteImage) . ' Downloaded OK</h3>';
   }else{
        echo '<h3 style="color: red;">Image ' . basename($remoteImage) . ' Download Failed</h3>';
    }
    #exit;
}
Zip("images/$ses_id/","images/$ses_id".".zip");
require_once('mailer/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded


$mail             = new PHPMailer();


// print "Body --> ".$body."<br>";
$body             = $text;
$body             = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = ""; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtpserver"; // sets the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username"; // SMTP account username
$mail->Password   = "password";        // SMTP account password


$mail->SetFrom('robot@mailmebot.com', 'teset');


$mail->AddReplyTo("robot@mailmebot.com","test");


$mail->Subject    = "Test Zip attachment";


$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test


$mail->MsgHTML($body);


$address = "dr.virus.india@gmail.com";
$mail->AddAddress($address, "");
#exit;
$mail->AddAttachment("images/$ses_id".".zip"); 


if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
  rrmdir("images/$ses_id");
}
function save_image($img,$fullpath='basename'){
    if($fullpath=='basename'){
      $fullpath = "images/$ses_id/";
        $fullpath .= basename($img);
    }
    $ch = curl_init ($img);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $rawdata=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($fullpath)){
        unlink($fullpath);
    }
    $fp = fopen($fullpath,'x');
    fwrite($fp, $rawdata);
    fclose($fp);
}


function rrmdir($dir) { 
   if (is_dir($dir)) { 
     $objects = scandir($dir); 
     foreach ($objects as $object) { 
       if ($object != "." && $object != "..") { 
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); 
       } 
     } 
     reset($objects); 
     rmdir($dir); 
   } 
}
function Zip($source, $destination)
{
    if (extension_loaded('zip') === true)
    {
        if (file_exists($source) === true)
        {
            $zip = new ZipArchive();


            if ($zip->open($destination, ZIPARCHIVE::CREATE) === true)
            {
                $source = str_replace('\\', '/', realpath($source));


                if (is_dir($source) === true)
                {
                    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);


                    foreach ($files as $file)
                    {
                        $file = str_replace('\\', '/', realpath($file));


                        if (is_dir($file) === true)
                        {
                            $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                        }


                        else if (is_file($file) === true)
                        {
                            $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                        }
                    }
                }


                else if (is_file($source) === true)
                {
                    $zip->addFromString(basename($source), file_get_contents($source));
                }
            }


            return $zip->close();
        }
    }


    return false;
}
?>

 

 

it gives an output like this.

 

 

Image genericlogo.png Downloaded OKImage sshot-17_thumb.png Downloaded OKImage sshot-6_thumb2.png Downloaded OKImage ip-300x225.jpg Downloaded OKImage sshot4ea03907359e9.png Downloaded OKImage ss-480-0-1-180x300.jpg Downloaded OKImage b1Z5FGDk-iphone3g-face-s-.png Downloaded OKImage sXoeeOzf-win7-s-.png Downloaded OKImage dxjWP0NG-exit-ex-s-.png Downloaded OKImage 817-windows-s-.png Downloaded OKImage images-4.jpg Downloaded OKImage 346510_700b.jpg Downloaded OKImage banner3.png Downloaded OKImage ?t=1318576167&i=20203 Download FailedImage paypal_transactions.png Download FailedImage ?t=1318595650&i=20227 Download FailedImage move_cloud_files.png Download FailedImage images-3.jpg Downloaded OKImage 8267.Windows_2D00_3.0_2D00_Task_2D00_List_5F00_th umb_5F00_6E7D7885.png Download FailedImage php.jpg Downloaded OKImage photo.jpg Downloaded OKImage hosting-badge-5.png Downloaded OKSMTP -> FROM SERVER:220 ESMTP Fri, 28 Oct 2011 02:37:24 -0400: UCE strictly prohibited

 

SMTP -> FROM SERVER: 250-authsmtp09.yourhostingaccount.com Hello localhost [122.181.6.50] 250-SIZE 34603008 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250-HELP 250 STARTTLS

 

 

 

Can somebody help me

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.