-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Отправка писем #235
Comments
Посмотри, вот тут: https://pear.php.net/manual/en/package.mail.mail-mime.example.php |
Друзья, я тут вернулся к вопросу почты, и методом проб и ошибок выяснил что наш Пример простого письма - две версии и вложение ниже: $mail =
MimeMail::create()->
addPart(
MimeMail::create()->setContentType('multipart/alternative')->
addPart(MimePart::create()->setBody('Text body')->setContentType('text/plain')->setCharset("UTF-8")->setEncoding(MailEncoding::base64()))->
addPart(MimePart::create()->setBody('<html><body><p>HTML <strong>body</strong></p></body></html>')->setContentType('text/html')->setCharset("UTF-8")->setEncoding(MailEncoding::base64()))->
build()
)->
addPart(MimePart::create()->setBody(file_get_contents($image->getThumbPath().$image->FileName))->setContentType(getimagesize($image->getThumbPath().$image->FileName)['mime'])->setEncoding(MailEncoding::base64())->setFilename($image->FileName)->setContentId(md5($image->getThumbPath().$image->FileName)))->
build();
Mail::create()->
setFrom(MailAddress::create()->setAddress('[email protected]')->setPerson('Отправитель')->toString())->
setTo('[email protected]')->
setSubject('Проверочное письмо')->
setHeaders($mail->getHeaders())->
setText($mail->getEncodedBody())->
send(); А что бы это чудо заработало необходима возможность указания svd@dsergey:/var/www/onPHP$ git diff main/Net/Mail/MimeMail.class.php
diff --git a/main/Net/Mail/MimeMail.class.php b/main/Net/Mail/MimeMail.class.php
index bfeb2ca..1773580 100644
--- a/main/Net/Mail/MimeMail.class.php
+++ b/main/Net/Mail/MimeMail.class.php
@@ -23,6 +23,32 @@
private $headers = null;
private $boundary = null;
+
+ private $contentType = null;
+
+ /**
+ * @return MimeMail
+ **/
+ public static function create()
+ {
+ return new self;
+ }
+
+ public function __construct()
+ {
+ // useful defaults
+ $this->contentType = 'multipart/mixed';
+ }
+
+ /**
+ * @return MimeMail
+ **/
+ public function setContentType($type)
+ {
+ $this->contentType = $type;
+
+ return $this;
+ }
/**
* @return MimeMail
@@ -34,17 +60,20 @@
return $this;
}
+ /**
+ * @return MimeMail
+ **/
public function build()
{
if (!$this->parts)
throw new UnimplementedFeatureException();
if (!$this->boundary)
- $this->boundary = '=_'.md5(microtime(true));
+ $this->boundary = '=_'.md5(microtime(true)*rand(1, 1000));
$mail =
MimePart::create()->
- setContentType('multipart/mixed')->
+ setContentType($this->contentType)->
setBoundary($this->boundary);
$this->headers =
@@ -59,6 +88,8 @@
.$part->getEncodedBody()."\n";
$this->body .= '--'.$this->boundary."--"."\n\n";
+
+ return $this;
}
|
$mail = HTML body ')->setContentType('text/html')->setCharset("UTF-8")->setEncoding(MailEncoding::base64()))->build() )-> addPart(MimePart::create()->setBody(file_get_contents($image->getThumbPath().$image->FileName))->setContentType(getimagesize($image->getThumbPath().$image->FileName)['mime'])->setEncoding(MailEncoding::base64())->setFilename($image->FileName)->setContentId(md5($image->getThumbPath().$image->FileName)))-> build(); Mail::create()-> Метод addPart в классе MimeMail явно ожидает объект MimePart , для и этого предусмотрен contentType в MimePart объекте. А в остальном не чего не изменилось возьмите почитайте RFC, если вы отправляете html с картинкой то лучше использовать 'multipart/related' а во всем остальном вам сюда https://github.com/onPHP/onphp-framework/blob/master/test/main/Net/MailTest.class.php |
Так я с этим и не спорю. Только в самом MimeMail при формировании письма первоначальный content-type захардкожен: https://github.com/onPHP/onphp-framework/blob/master/main/Net/Mail/MimeMail.class.php#L47 |
Это если картинка предполагается использоваться в теле письма, если просто вложением - то нет $mp2 =
MimePart::create()->
loadBodyFromFile($image2->getThumbPath().$image2->FileName)->
setContentType(getimagesize($image2->getThumbPath().$image2->FileName)['mime'])->
setEncoding(MailEncoding::base64())->
setContentId(md5($image2->getThumbPath().$image2->FileName).image_type_to_extension(getimagesize($image2->getThumbPath().$image2->FileName)[2]))->
setInline();
$mail =
MimeMail::create()->
addPart(
MimeMail::create()->setContentType('multipart/alternative')->
addPart(MimePart::create()->setBody('Text body')->setContentType('text/plain')->setCharset("UTF-8")->setEncoding(MailEncoding::base64()))->
addPart(
MimeMail::create()->setContentType('multipart/related')->
addPart(MimePart::create()->setBody('<html><body><p>HTML <strong>body</strong><br /><img src="cid:'.$mp2->getContentId().'" alt="" /></p></body></html>')->setContentType('text/html')->setCharset("UTF-8")->setEncoding(MailEncoding::base64()))->
addPart($mp2)->
build()
)->
build()
)->
addPart(MimePart::create()->loadBodyFromFile($image->getThumbPath().$image->FileName)->setContentType(getimagesize($image->getThumbPath().$image->FileName)['mime'])->setEncoding(MailEncoding::base64())->setFilename($image->FileName))->
build(); |
Друзья!
Дайте пример отправки письма с вложением (картика в частности). Простые письма отправляю не вопрос. Посмотрел все что с mail связано, видел MimeMail, но как пользоваться не понял
The text was updated successfully, but these errors were encountered: