Last active
May 5, 2023 08:31
-
-
Save silverliebt/6709658 to your computer and use it in GitHub Desktop.
Example setup of phpmailer using vars (from session vars) on conversion page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHPMailer | |
* @package phpmailer | |
* @version $Id$ | |
*/ | |
require 'phpmailer/class.phpmailer.php'; | |
try { | |
$mail = new PHPMailer(true); //New instance, with exceptions enabled | |
$body = file_get_contents('phpmailer/subfolder/htmlemailfile.html'); | |
$body = str_replace('$fullname', $fullname, $body); | |
$body = str_replace('$title', $title, $body); | |
$body = str_replace('$email', $email, $body); | |
$body = str_replace('$company', $company, $body); | |
$body = str_replace('$site', $site, $body); | |
$body = str_replace('$address', $address, $body); | |
$body = str_replace('$suite', $suite, $body); | |
$body = str_replace('$city', $city, $body); | |
$body = str_replace('$state', $state, $body); | |
$body = str_replace('$zip', $zip, $body); | |
$body = str_replace('$country', $country, $body); | |
$body = str_replace('$phone', $phone, $body); | |
$body = str_replace('$comments', $comments, $body); | |
$body = str_replace('$utm_source', $utm_source, $body); | |
$body = str_replace('$utm_medium', $utm_medium, $body); | |
$body = str_replace('$utm_campaign', $utm_campaign, $body); | |
$body = str_replace('$utm_content', $utm_content, $body); | |
$body = str_replace('$keyword', $keyword, $body); | |
$body = str_replace('$ip', $ip, $body); | |
$body = str_replace('$hostname', $hostname, $body); | |
$body = preg_replace('/\\\\/','', $body); //Strip backslashes | |
$mail->IsSMTP(); // tell the class to use SMTP | |
$mail->SMTPAuth = true; // enable SMTP authentication | |
$mail->SMTPSecure = 'ssl'; // type of secure SMTP connection | |
$mail->Port = 465; // set the SMTP server port | |
$mail->Host = "serverhere"; // SMTP server | |
$mail->Username = "youremail@account.com"; // SMTP server username | |
$mail->Password = "y0urp@sswrd"; // SMTP server password | |
// $mail->IsSendmail(); // tell the class to use Sendmail | |
$mail->AddReplyTo("$email"); | |
$mail->From = "info@company.com"; | |
$mail->FromName = "Company"; | |
$to = "$email"; | |
$mail->AddAddress($to); | |
$mail->AddBCC('joe@example.com'); | |
$mail->AddBCC('janet@example.com'); | |
// full name appears in email subject header if company missing | |
if (!empty($company)) { | |
$mail->Subject = "Customer Application - $company"; | |
} | |
else { | |
$mail->Subject = "Customer Application - $fullname"; | |
} | |
// $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test | |
// $mail->WordWrap = 80; // set word wrap | |
$mail->MsgHTML($body); | |
$mail->IsHTML(true); // send as HTML | |
$mail->CharSet="utf-8"; // use utf-8 character encoding | |
if(!empty($email)) { | |
$mail->Send(); | |
} | |
// echo 'Message has been sent.'; | |
echo "<br>"; | |
} catch (phpmailerException $e) { | |
echo $e->errorMessage(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment