Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP If statement within HTML Email

How do I add PHP code into an HTML email that is sent out via PHP?

The following does not work:

			$to = 'ME@ME.com';
			
			$subject = 'MY SUBJECT';
			
			$headers = "From: ME\r\n";
			$headers .= "Reply-To: help@ME.com\r\n";
			$headers .= "MIME-Version: 1.0\r\n";
			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
			$message =	'<html><body>';
			$message .= '<h1>Thank you for your purchase</h1>
							<table>
								<tr>
									<td>TD Image One ONE</td>
									<td>TD Image TWO </td>
								</tr>
								
								<tr>
									<td><img src="MY-IMAGE/GC-25.jpg"/></td>
									<td>';
									if ($item-name=="CI50") {
										echo '<img src="MY-IMAGEGC-50.jpg"/><br />'.$gon;
										} else {
											echo 'No Image Available';
										}
										echo '</td>
								</tr>
							</table>';
			$message .= '</html></body>';
				
				mail($to, $subject, $message, $headers);		
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Frosty555
Frosty555
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

@Frosty  I guess If I had really thought about it, I would have come up with this.  However, thank you for pointing me in the correct and logical direction.

On another note, in an HTML email sent out via PHP where do I place the <style>? In the header?
Avatar of Dave Baldwin
Gmail blocks <style> tags completely and more block style <links>.  See here: http://www.campaignmonitor.com/css/  Inline styles are supported to varying degrees.