Jump to content

Recommended Posts

Hi all,

 

I'm having a problem sending email using php mail. The email is designed with tables so I'm using inline CSS styles. Problem is that the styles do not work. It gets displayed as text.

 

Example:

<?php
$email_temp = '<html>
<head>
</head>
<body>
<table style="border:solid; border-color:#AD9090; border-left-width: 4px;
border-right-width: 4px; border-top-width: 0px;
border-bottom-width: 0px;" width="700" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td> </td>
  </tr>
</table>
</body>
</html>';


mail($email, "Newsletter", $email_temp, "From: [email protected]" );

if(mail($email, "Newsletter", $email_temp, "From: [email protected]" )){
    echo "The email was successfully sent.";
} else {
    echo "The email was NOT sent.";
}
?>

 

This displays the style as text instead of the required borders eg. border-right-width: 4px; border-top-width: 0px; border-bottom-width: 0px;" width="700" border="0" cellspacing="0" cellpadding="0">

 

Also the email gets sent twice and I know it is because of the if clause but I'm not sure how else to put it.

 

Please help.

I wish that could be it, tried it and still the same thing, I'm sure the style is closed with the double quotes correctly. I echoed it with php and the table style displays fine. Also when I send the email normally (without php code) as plain html the table style displays fine (I'm using hotmail to test this). The style displays as text only when I use the mail function. So now I know where the problem is only question is how do I resolve this?

 

Any ideas? Anyone?  ???

The email is sending twice because this:

mail($email, "Newsletter", $email_temp, "From: [email protected]" );

 

sends the mail, and then your if clause:

if(mail($email, "Newsletter", $email_temp, "From: [email protected]" )){

 

sends it again. The solution is this:

 

$result = mail($email, "Newsletter", $email_temp, "From: [email protected]" );

if ($result) {

 

Hey Kerblam,

 

Thanks for the help, the email now gets sent once.

 

I'm still having trouble with the CSS styles. The CSS style still shows as text. I'm searching the forum but I still haven't found anything similar to this issue unless theres something I've missed.

From php.net:

 

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";

 

Then...

 

$result = mail($email, "Newsletter", $email_temp, $headers);

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.