Home » Php » blur image is not showing while sending mail

blur image is not showing while sending mail

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am using following code for making image blur.

if(exif_imagetype($filepath) != IMAGETYPE_JPEG){
            //header('Content-Type: image/png');
            $file = $filepath;
            $image = imagecreatefrompng($filepath);
        } else {
            //header('Content-Type: image/jpeg');
            $file = $filepath;
            $image = imagecreatefromjpeg($filepath);
        }

        /* Get original image size */
        list($w, $h) = getimagesize($file);

        /* Create array with width and height of down sized images */
        $size = array('sm'=>array('w'=>intval($w/4), 'h'=>intval($h/4)),
            'md'=>array('w'=>intval($w/2), 'h'=>intval($h/2))
        );

        /* Scale by 25% and apply Gaussian blur */
        $sm = imagecreatetruecolor($size['sm']['w'],$size['sm']['h']);
        imagecopyresampled($sm, $image, 0, 0, 0, 0, $size['sm']['w'], $size['sm']['h'], $w, $h);

        for ($x=1; $x <=5; $x++){
            imagefilter($sm, IMG_FILTER_GAUSSIAN_BLUR, 999);
        }

        imagefilter($sm, IMG_FILTER_SMOOTH,99);
        imagefilter($sm, IMG_FILTER_BRIGHTNESS, 10);

        /* Scale result by 200% and blur again */
        $md = imagecreatetruecolor($size['md']['w'], $size['md']['h']);
        imagecopyresampled($md, $sm, 0, 0, 0, 0, $size['md']['w'], $size['md']['h'], $size['sm']['w'], $size['sm']['h']);
        imagedestroy($sm);

        for ($x=1; $x <=5; $x++){
            imagefilter($md, IMG_FILTER_GAUSSIAN_BLUR, 999);
        }

        imagefilter($md, IMG_FILTER_SMOOTH,99);
        imagefilter($md, IMG_FILTER_BRIGHTNESS, 10);

        /* Scale result back to original size */
        imagecopyresampled($image, $md, 0, 0, 0, 0, $w, $h, $size['md']['w'], $size['md']['h']);
        imagedestroy($md);

        ob_start();
        imagejpeg($image);
        imagedestroy($image);
        $png = ob_get_clean();
        $uri = "data:image/jpeg;base64," . base64_encode($png);

Which is working very well on web. I am sending mail using phpmailer but when I am trying to send these blur images to other’s email then blur images not showing in those emails. I am unable to understand why this is happening. Please suggest something for this issue.

I have tried this code for sending mail. I am getting email properly but blur images not showing there.

require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                            // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';             // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                     // Enable SMTP authentication
$mail->Username = 'Email Address';          // SMTP username
$mail->Password = 'Email Account Password'; // SMTP password
$mail->SMTPSecure = 'tls';                  // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                          // TCP port to connect to

$mail->setFrom('[email protected]', 'CodexWorld');
$mail->addReplyTo('[email protected]', 'CodexWorld');
$mail->addAddress('[email protected]');   // Add a recipient
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

$mail->isHTML(true);  // Set email format to HTML

$bodyContent = '<h1>How to Send Email using PHP in Localhost by CodexWorld</h1>';
$bodyContent .= '<p>This is the HTML email sent from localhost using PHP script by <b>CodexWorld</b></p>';

$mail->Subject = 'Email from Localhost by CodexWorld';
$mail->Body    = $bodyContent;

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

https://www.codexworld.com/how-to-send-email-from-localhost-in-php/

Answers: