Ben kendi satış personeli son derece tasarlanmış 2 sütun html şablonlar doldurmak ve bu kullanarak e-postalar göndermek mümkün istedim bir istemci var. E-posta başına 6 alıcıları max.
Onlar ayrı alıcıların her göndermek istediğiniz karar kadar çözüm çok iyi çalıştı. Hayır CC, BCC yok.
Ben bunun yerine döngü olur önce ben sadece adresleri dizi göçmüştü nerede düşündüm ama bu boş içerikli e-postalar üretti. Konu satırı iyiydi ama içerik sıfır bayt oldu.
I () bir kalıba yerleştirin ve ekrana $ html_text atacaksan İlginçtir ben içerik olarak olmasını beklediğiniz görüyoruz.
Başlangıçta ben döngü dışında, konu vb içeriği ayarlayabilirsiniz ama boş içeriği görünce, bu bana hiç mantıklı olsa belki ben döngü içinde değişkenler ayarlamak gerektiğini düşündüm. Hiçbir şey değişti.
İşte döngü kodu:
if (count($_SESSION['recipients']) > 0) {
foreach ($_SESSION['recipients'] as $to) {
$template = $_SERVER['DOCUMENT_ROOT'] . '/leads/templates/'.$_SESSION['templateFile'];
ob_start();
include($template);
$html = ob_get_contents();
ob_end_clean();
if (strlen($html) == 0) {
echo "The template at $template did not load.";
exit;
}
$bullets = unslash($_SESSION['bullets']);
$bullets = preg_replace('/<li>/', '* ', $bullets);
$bullets = strip_tags($bullets);
$TextMessage = strip_tags(unslash($_SESSION['message'])) . "\n\n" . $bullets;
$notice_text = "This is a multi-part message in MIME format.";
$plain_text = str_replace(' ',' ', $TextMessage);
$html_text = $html;
$email = $_SESSION['user']->email;
$name = $_SESSION['user']->first_name . ' ' . $_SESSION['user']->last_name;
$from = "$name <$email>";
$subject = unslash($_SESSION['subject']);
$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);
$body = "$notice_text
--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
$plain_text
--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
$html_text
--$mime_boundary--";
if (@mail($to, $subject, $body,
"From: " . $from . "\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=" . $mime_boundary_header)) {
$out .= " Email sent to " . htmlentities($to) . ".<br />";
} else {
$out .= " Email to htmlentities($to) NOT sent successfully!";
}
} // foreach
Herhangi bir tavsiye çok takdir!
2010.08.06 - EDIT: Ben sert kodlu metin ile $ html_text ve $ plain_text değiştirmeyi denedim ve aynı sonuçları bulduk: Boş mail gönderdi. Ayrıca hiçbir başarı ile döngü dışında $ mime_boundary ve $ mime_boundary_header nesil hareketli çalıştı.
Ben boş posta gönderilir die('<pre>'.$body.'</pre>'); hemen sonra eklerseniz Ancak ben HTML ve metin ve sınırları beklediğiniz her şeyi görmek ... İşte bir örnek:
This is a multi-part message in MIME format.
--==MULTIPART_BOUNDARY_94e43eed6cf2826fc5787c860814066e
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
My plain text here
* Bullet point 1
* Bullet point 2
--==MULTIPART_BOUNDARY_94e43eed6cf2826fc5787c860814066e
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
// RENDERED HTML CONTENTS SHOW UP HERE