我正在使用PHPMailer发送邮件,我的代码如下:
<form method="post" action="" id="myform">
<label for="name">Objet:</label>
<input type="text" name="subject" id="subject" class="input validate[required] TextInput" />
<label for="email">Destinataire:</label>
<input type="text" name="email" id="email" class="input validate[required,custom[email]] text-input" />
<label for="about">Message:</label>
<textarea name="about" id="about" rows="4" cols="40" class="validate[required] text-input">
<?php
while($data = mysql_fetch_array($result)){
echo $data['valeur'];
}
?>
</textarea>
<p><input type="submit" name="submit" value="Envoyer" class="btnValider"/></p>
</form>
<?php
// copy file pdf from http://archi-graphi.com/arcancianev/pdf.php to new file sejour.pdf
$ourFileName = "Collaborateur.pdf";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$htmlFile = file_get_contents('http://www.archi-graphi.com/activite/v1/pdfCola.php?projet_id='.$_REQUEST['id']);
//$pdfHtml = ('sejour.pdf');
file_put_contents($ourFileName,$htmlFile);
fclose($ourFileHandle);
// end copy
if(isset($_POST['submit'])){
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $_POST['about'];
$mail->CharSet="windows-1251";
$mail->CharSet="utf-8";
$mail->AddReplyTo("maly.nu_cute@ymail.com","Maly");
$mail->SetFrom('maly.nu_cute@ymail.com', 'Maly');
$mail->AddReplyTo("maly.nu_cute@ymail.com","Maly");
$address = $_POST['email'];
$mail->AddAddress($address, $address);
$mail->Subject = $_POST['subject'];
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("Collaborateur.pdf"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message envoyé!";
}
}
?>
在消息中,我使用textarea它的值我从包含CSS代码的数据库中获取它。当我发送邮件它有效但风格css它不像字体颜色那样工作它不显示,我不知道如何解决这个问题?有人请帮助我,谢谢。
答案 0 :(得分:1)
默认情况下,PHP mail()
函数为text/plain
。在mail()
标题中,将内容类型更改为text/html
并尝试。为此,请添加以下代码。
$mail->IsHTML(true);
您应该使用电子邮件中的外部CSS文件。尝试内联CSS
<p style="color:sienna;margin-left:20px">This is a paragraph.</p>
答案 1 :(得分:0)
我认为你应该补充说你的电子邮件是html。在调用send之前尝试添加以下内容:
$mail->IsHTML(true);
答案 2 :(得分:0)
$mail->IsHTML(true);
试试这个