Code Monkey home page Code Monkey logo

Comments (11)

eoghanobrien avatar eoghanobrien commented on June 1, 2024

Hi @mazandnet, can you provide a test case that reproduces the error.

from php-simple-mail.

mazandnet avatar mazandnet commented on June 1, 2024

I can test and send email to you . What is your mail?

from php-simple-mail.

eoghanobrien avatar eoghanobrien commented on June 1, 2024

Just provide the code (parameters) you're using to send the email.

from php-simple-mail.

mazandnet avatar mazandnet commented on June 1, 2024

from php-simple-mail.

eoghanobrien avatar eoghanobrien commented on June 1, 2024

Thanks, which client are you seeing the issue.

from php-simple-mail.

mazandnet avatar mazandnet commented on June 1, 2024

I am useing this in my localhost on windows 10
whith this code i can send attache but this code don't send html emails :

final class SMail {
      
      public $attachment_name;

      public $attachment_path;

    
      public $body;

   
      public $error;

     
      public $from;

     
      public $subject;

     
      public $to;

      
      public function send() {
            // check for valid params
            if($this->to) {
                  // set boundry
                  $boundary = md5(rand(5000, 500000000) . time());

                  // set attachment if exists
                  $attachment = null;
                  if($this->attachment_path && $this->attachment_name) {
                        // check if attachment file exists
                        if(file_exists($this->attachment_path)) {
                              $attachment = chunk_split(base64_encode(file_get_contents($this->attachment_path)));
                        } else {
                              $this->error = "Failed to send mail, attachment file \"{$this->attachment_path}\" not found";
                              return false;
                        }
                  }

                  // set headers
                  $headers = null;
                  if($this->from) {
                        $headers = "From: {$this->from}\r\nReply-To: {$this->from}";
                  }
                  if($attachment) {
                        $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_{$boundary}\"";
                  }

                  // set body
                  $body = null;
                  if($attachment) {
                        $body = "This is a multi-part message in MIME format.

--_1_{$boundary}
Content-Type: multipart/alternative; boundary=\"_2_{$boundary}\"

--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

{$this->body}

--_2_{$boundary}--
--_1_{$boundary}
Content-Type: application/octet-stream; name=\"{$this->attachment_name}\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

{$attachment}
--_1_{$boundary}--";
                  } else {
                        $body = $this->body;
                  }

                  // send mail
                  if(mail($this->to, $this->subject, $body, $headers)) {
                        return true;
                  } else {
                        $this->error = "Failed to send mail (check SMTP settings)";
                        return false;
                  }

            // fail
            } else {
                  $this->error = "Failed to send mail, invalid params";
                  return false;
            }
      }
}

from php-simple-mail.

eoghanobrien avatar eoghanobrien commented on June 1, 2024

Which e-mail client are you using? e.g. Outlook, Mac Mail etc

from php-simple-mail.

mazandnet avatar mazandnet commented on June 1, 2024

from php-simple-mail.

eoghanobrien avatar eoghanobrien commented on June 1, 2024

I'm not sure what the code you referenced above is from but it's not using SimpleMail so I can't help you with that.

I just tested using your exact code and it works as expected in Gmail, Mail (Mac) and Outlook 2017 (Mac)

I think you should look into how the mail() function is working in your Windows environment

from php-simple-mail.

mrforsythexeter avatar mrforsythexeter commented on June 1, 2024

I am seeing this same problem with gmail (not tested other clients yet).

$mail = new SimpleMail();
	$mail
		->setSubject('Performance Report For Date Range')
		->setFrom('[email protected]', 'XXXXXX - Reports')
		->addGenericHeader('X-Mailer', 'PHP/' . phpversion())
		->addGenericHeader('X-Script', 'daily_reports.php')
		->addGenericHeader('Content-Type', 'text/html; charset="utf-8"')
		->addAttachment('tempfile','performance_report.xls')
		->setMessage('Performance Report For Date Range is attached')
		->setWrap(78);


		$mail->setTo('[email protected]', 'XXXXX');

	$send = $mail->send();

I am on CentOS Linux release 7.4.1708 using php PHP 7.1.8

The result is that the content of $headers on line 505 is in the message as content.

I have tried replacing PHP_EOL with "\r\n" however this had no effect.

I am attaching an xlsx if that makes any difference

from php-simple-mail.

mrforsythexeter avatar mrforsythexeter commented on June 1, 2024

Ignore the above, I know what the issue is. Maybe the code should watch for this, but can't hold everyone's hand.

basically I was setting the content-type..

->addGenericHeader('Content-Type', 'text/html; charset="utf-8"')

which was applied to the email headers before the attachments headers, so the content was being treated as 'text/html' and quite rightly!

from php-simple-mail.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.