tags:

views:

36

answers:

2

Hello,

I have developed a competition page for a client, and they wish for the email the customer receives be more than simply text. The tutorial I used only provided simple text, within the 'send body message'. I am required to add html to thank the customer for entering, with introducing images to this email.

The code is:

//send the welcome letter
function send_email($info){

    //format each email
    $body = format_email($info,'html');
    $body_plain_txt = format_email($info,'txt');

    //setup the mailer
    $transport = Swift_MailTransport::newInstance();
    $mailer = Swift_Mailer::newInstance($transport);
    $message = Swift_Message::newInstance();
    $message ->setSubject('Thanks for entering the competition');
    $message ->setFrom(array('[email protected]' => 'FromEmailExample'));
    $message ->setTo(array($info['email'] => $info['name']));

    $message ->setBody('Thanks for entering the competition, we will be in touch if you are a lucky winner.');

    $result = $mailer->send($message);

    return $result;

}

This function.php sheet is working and the customer is recieving their email ok, I just need to change the

('Thanks for entering the competition, we will be in touch if you are a lucky winner.')

to have HTML instead...

Please, if you can, provide me with an example of how I can integrate HTML into this function.

Cheers in advance. :-)

A: 

Will the same text remain or should it be styled somehow? Editing your emails in html requires inline css styles eg:

('<p style="font-size:1.2em; color:#f0f0f0;">Thanks for entering the competition, we will be in touch if you are a lucky winner.</p>')

if you need a table just add:

('<table style="font-size:1.2em; color:#f0f0f0;"><tr><td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td></tr></table>')

or to make it more simpler

$message_body'
<table style="font-size:1.2em; color:#f0f0f0;">
<tr>
<td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td>
</tr>
</table>
';

$message ->setBody($message_body);

I know that when I need to send html emails I need to set the content-type to html which I believe you did on the following line

$body = format_email($info,'html');

I hope this is what you were looking for. if not let me know

krike
Hi Krike,Thanks for getting back to me, I have tried this method of typing in the table code to the function, and basically the email I recieve then shows me the tags, instead of using the tags to style the text?? Do you know any other way around this?
Daniel
It's OK, I got it working. Thanks a lot for your help Krike. :-)
Daniel
Glad you could make it work, i thought the content type was allready set to html but I guess it was not seeing galens reply.
krike
A: 
$message = Swift_Message::newInstance();
$message->setContentType('text=html');
Galen
Hi Galen, thanks for your fast reply, I'm unsure where I should insert this? Should I remove any lines and replace them with your suggestion?
Daniel
edited my answer, you should see where to add it now
Galen
Great Galen, thanks a lot. :-)
Daniel
accept the answer!
Galen