Jump to content

Recommended Posts

okay i dont know where to put this topic, if it needs to be moved then please do so, I have been creating a mass mailer with this class, 

<?php
class SimpleMail
{
    private $toAddress;
    private $CCAddress;
    private $BCCAddress;
    private $fromAddress;
    private $subject;
    private $sendText;
    private $textBody;
    private $sendHTML;
    private $HTMLBody;

    public function __construct() {
        $this->toAddress = '';
        $this->CCAddress = '';
        $this->BCCAddress = '';
        $this->fromAddress = '';
        $this->subject = '';
        $this->sendText = false;
        $this->textBody = '';
        $this->sendHTML = true;
        $this->HTMLBody = '';
    }

    public function setToAddress($value) {
        $this->toAddress = $value;
    }

    public function setCCAddress($value) {
        $this->CCAddress = $value;
    }

    public function setBCCAddress($value) {
        $this->BCCAddress = $value;
    }

    public function setFromAddress($value) {
        $this->fromAddress = $value;
    }

    public function setSubject($value) {
        $this->subject = $value;
    }

    public function setSendText($value) {
        $this->sendText = $value;
    }

    public function setTextBody($value) {
        $this->sendText = false;
        $this->textBody = $value;
    }

    public function setSendHTML($value) {
        $this->sendHTML = $value;
    }

    public function setHTMLBody($value) {
        $this->sendHTML = true;
        $this->HTMLBody = $value;
    }

    public function send($to = null, $subject = null, $message = null,
        $headers = null) {

        $success = false;
        if (!is_null($to) && !is_null($subject) && !is_null($message)) {
            $success = mail($to, $subject, $message, $headers);
            return $success;
        } else {
            $headers = array();
            if (!empty($this->fromAddress)) {
                $headers[] = 'From: ' . $this->fromAddress;
            }

            if (!empty($this->CCAddress)) {
                $headers[] = 'CC: ' . $this->CCAddress;
            }

            if (!empty($this->BCCAddress)) {
                $headers[] = 'BCC: ' . $this->BCCAddress;
            }

            if ($this->sendText && !$this->sendHTML) {
                $message = $this->textBody;
            } elseif (!$this->sendText && $this->sendHTML) {
                $headers[] = 'MIME-Version: 1.0';
                $headers[] = 'Content-type: text/html; charset="iso-8859-1"';
                $headers[] = 'Content-Transfer-Encoding: 7bit';
              //  $headers[] .= 'Content-Transfer-Encoding: quoted-printable';
                $message = $this->HTMLBody;
            } elseif ($this->sendText && $this->sendHTML) {
                $boundary = '==MP_Bound_xyccr948x==';
                $headers[] = 'MIME-Version: 1.0';
                $headers[] = 'Content-type: multipart/alternative; boundary="' .
                    $boundary . '"';

                $message = 'This is a Multipart Message in MIME format.' . "\n";
                $message .= '--' . $boundary . "\n";
                $message .= 'Content-type: text/plain; charset="iso-8859-1"' . "\n";
                $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
               // $message .= 'Content-Transfer-Encoding: quoted-printable' . "\n\n";
                $message .= $this->textBody  . "\n";
                $message .= '--' . $boundary . "\n";

                $message .= 'Content-type: text/html; charset="iso-8859-1"' . "\n";
                $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
                $message .= $this->HTMLBody  . "\n";
                $message .= '--' . $boundary . '--';
            }

            $success = mail($this->toAddress, $this->subject, $message,
                join("\r\n", $headers));
            return $success;
        }
    }
}
?>

now the problem is when ever gmail recives the image code , 

<img src="http://yourdomain.com/image.jpg" >

it escapes them like this :

<img src=\"http://yourdomain.com/image.jpg\" >

and the image is not read how could i resolve this ???

Edited by cyber_alchemist
Link to comment
https://forums.phpfreaks.com/topic/285544-html-emails-help-bit-urgent/
Share on other sites

Gmail is usually pretty loose in terms of letting email go through as is. So, you are saying the email works with all other email providers? Are you sure that you are not the one slashing the quotes before it is sent? For instance, if you have magic quotes enabled on your server, it could be you. Have you tried a different email class? I use swiftmailer, which is quite popular.

This sounds like gmail's built-in warding against images. It's actually common in a lot of email providers, to prevent display of images unless the visitor clicks a button to enable them (or sets it to allow in their email settings). The reason is because in order to show images in an email, the image must be downloaded to the user's browser or email client (e.g. outlook). Images can possibly contain viruses or malware. More common though is that companies usually use images in emails as a way to track when users read the emails they send out. Well you know how much everybody likes having their activities tracked. Anyways, the point is that it's likely not a problem with your code, but a "problem" with gmail's (and other email providers) policy about displaying images in the email.

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.