How to do Mail Merge with php and MySQL
I have googled this to death already and cannot find any answers, so I am hoping the DD geniuses can save the day.
What is the correct way without using global variables (eregi_replace has been deprecated) to get data from a MySQL database into variables in an html email? There are no $_POST or $_GET variables. I tried using echo with php but it would appear php does not work in an html email.
I had been using the following code (which I never really understood & may have been awful in the first place) and would really like to learn the best possible way. I don't like having Register Globals = On in the php.ini but everything goes blank if I turn it off. Thanks!
Code:
@$fp = fopen($html_email_template_file, "r");
while(!feof($fp)) {
$buffer = fgets($fp,100);
$body.= $buffer;
}
fclose ($fp);
$body = replace_email_template_variables($body);
$Subject = "Your Quote Request";
$mail = new phpmailer();
$mail->From = "info@domain.com";
$mail->FromName = "Company Name";
$mail->AddAddress($_POST['Email'], $name);
$mail->AddReplyTo('info@domain.com', 'Company Name');
$mail->IsHTML(true);
$mail->Subject = $Subject;
$mail->Body = $body;
$mail->Send();