link in the following message:

Include html in email

I need to include some HTML things in PHP, for example, add a <a href="#">link</a> in the following message:

 <?php $to = $themail; $subject = "Expiration d'une annonce"; $body = "Hey,\n\n"; // I need to include a link here in the body like <a href ="http://www.www.com"> Link </a> mail($to, $subject, $body) ?> 

Any ideas?

0
source share
4 answers

I suggest using PHPMailer, easy to use, takes care of all nesseccery headers, simple insertion, multiple recipients, etc.

http://phpmailer.worxware.com/index.php?pg=phpmailer

+4
source

It is very simple: mail()

Set the correct headers (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"; // Mail it mail($to, $subject, $message, $headers); 

your $ message may now contain HTML. For complex html / email, it is recommended to use some packages, for example, the PEAR Mailer class.

+2
source

I do not understand. Do you need an echo in html like this?

 echo '<a href ="http://www.www.com"> Link </a>'; 

Or you need to do this:

 $body .= '<a href ="http://www.www.com"> Link </a>'; 

What exactly are you trying to do?

If you are trying to send HTML data via mail (), you need to set some headers

  $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf8' . "\r\n"; mail($to, $subject, $body, $headers); 

For more information, check http://php.net/manual/en/function.mail.php example 4

+1
source

php.net/mail has many examples

 <?php // multiple recipients $to = ' aidan@example.com ' . ', '; // note the comma $to .= ' wez@example.com '; // subject $subject = 'Birthday Reminders for August'; // message $message = ' <html> <head> <title>Birthday Reminders for August</title> </head> <body> <p>Here are the birthdays upcoming in August!</p> <table> <tr> <th>Person</th><th>Day</th><th>Month</th><th>Year</th> </tr> <tr> <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> </tr> <tr> <td>Sally</td><td>17th</td><td>August</td><td>1973</td> </tr> </table> </body> </html> '; // 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"; // Additional headers $headers .= 'To: Mary < mary@example.com >, Kelly < kelly@example.com >' . "\r\n"; $headers .= 'From: Birthday Reminder < birthday@example.com >' . "\r\n"; $headers .= 'Cc: birthdayarchive@example.com ' . "\r\n"; $headers .= 'Bcc: birthdaycheck@example.com ' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?> 

I also found this article helpful:

PHP: sending email (text / HTML / attachments)

+1
source

All Articles