PDA

View Full Version : سوال: چگونگی ساخت ایمیل های زیبا با phpmailer



comp90
شنبه 16 مرداد 1395, 21:04 عصر
سلام و درود:

بعضی از سایت ها ایمیل فعالسازی حسابشن خیلی زیباست چگونه میشه اینگونه ایمیل هارو طراحی کرد؟

من با ارسال ایمیل توسط phpmailer مشکلی ندارم ولی وقتی در قسمت body کدهای html رو به همراه style قرار می دم کدهای css اون اعمال نمیشه در ایمیل ارسالی.

چگونه میشه تصویر لود کرد ؟ آیکون ؟ رنگ و لعاب در هدر ایمیل؟

ممنون میشم اگر کمک کنید

کدهای html رو بین اینگونه قرار میدم:

$mail->Body = <<<EOS

کدهای اچ تی ام ال


EOS;

مهرداد سیف زاده
یک شنبه 17 مرداد 1395, 06:43 صبح
کد زیر رو تست کنید


$body = <<< YOUR_HTML_WITH_CSS_STYLE_TAGS
<html>
<head>
<style>
body * {width:1px;}
#adiv {padding:2px;}
.aclass {margin:3px;}
</style>
</head>
<body>
<div>
some html
</div>
<div id="adiv">
<p class="aclass">
</p>
</div>
</body>
</html>
YOUR_HTML_WITH_CSS_STYLE_TAGS;
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpd = new DOMXPath($doc);
0&&$node = new DOMElement();
$result = $xpd->query('//img');
foreach($result as $node){
$attr = $node->getAttribute('src');
$re = '/(http:\/\/.*?)?(\/.*+)/i';
if(preg_match_all($re, $attr, $matches)){
if(!empty($matches[1][0])&&0)
continue;
$attr = 'http://'.$_SERVER['HTTP_HOST'].$matches[2][0];
}
$node->setAttribute('src',$attr);
}
false&&$node=new DOMElement()&&$child=new DOMElement();
$result = $xpd->query('//style/..');
foreach($result as $node){
foreach($node->childNodes as $child){
if(strtolower($child->nodeName)=='style'){
$node->removeChild($child);
$css = $child->textContent;
$re = '/(.*?)\{([^}]+)\}/';
if(preg_match_all($re, $css, $matches)){
foreach($matches[1] as $idx=>$css_selector){
$css_text = $matches[2][$idx];
$css_text = preg_replace('/\s+/',' ',$css_text);
$css = new CSSQuery($doc);
foreach($css->query($css_selector) as $selected_node){
$style = $selected_node->getAttribute('style');
$selected_node->setAttribute('style', $style?$css_text:$style.';'.$css_text);
}
}
}
}
}
}
$body = $doc->saveHTML();


http://stackoverflow.com/questions/358788/how-can-i-send-html-mails-with-included-css-with-phpmailer
https://github.com/PHPMailer/PHPMailer/issues/400