Comments (11)
Hi @mazandnet, can you provide a test case that reproduces the error.
from php-simple-mail.
I can test and send email to you . What is your mail?
from php-simple-mail.
Just provide the code (parameters) you're using to send the email.
from php-simple-mail.
from php-simple-mail.
Thanks, which client are you seeing the issue.
from php-simple-mail.
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.
Which e-mail client are you using? e.g. Outlook, Mac Mail etc
from php-simple-mail.
from php-simple-mail.
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.
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.
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)
- Bcc header not being set HOT 1
- Quotation marks in subject lines are entity-encoded HOT 1
- Multiple recipients in Cc & Bcc HOT 1
- Outlook untitled attachment HOT 2
- safe HOT 1
- Fatal Error when sending email HOT 2
- Attachments in default mail client Mac OS HOT 2
- The make() function is redundant HOT 1
- Gmail and Yahoo not receiving messages HOT 2
- Email not secure HOT 1
- Send mail after form validation. HOT 2
- "Content-Type: multipart/alternative" to send both text and html format ? HOT 1
- Add attachment with setHtml() not work HOT 1
- encodeUtf8Word() should prefer ASCII when possible
- No license HOT 1
- fix $this->please HOT 4
- send mail to multiple addresses HOT 2
- Problems with sending attachments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-simple-mail.