Reputation: 77
I'm using PHPMailer for sending mail, I have code as below:
<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("[email protected]","Maly");
$mail->SetFrom('[email protected]', 'Maly');
$mail->AddReplyTo("[email protected]","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é!";
}
}
?>
In the message, I use textarea that its value I take it from database that contain the CSS code with it.when I send mail it works but the style css it not work like font color it not displays, I do not know how to fix this?Anyone help me please, Thanks.
Upvotes: 2
Views: 4496
Reputation: 45124
By default, the PHP mail()
function is text/plain
. In your mail()
headers, change the content-type to text/html
and try. To do that add the below code.
$mail->IsHTML(true);
Also You should'nt work with external CSS files in emails. Try inline CSS
<p style="color:sienna;margin-left:20px">This is a paragraph.</p>
Upvotes: 1
Reputation: 1849
I think you should add that your email is html. Try adding below before calling send:
$mail->IsHTML(true);
Upvotes: 0