If you are using PHP MAILER class and tired of the same old HTML static blah! blah content. Me and my officemate (give credit…) configured how we can use the same class but passing a dynamic content to that.
function mailer($rdate,$first, $last, $middlename, $emailadd, $message, $username, $password, $ReplyTo, $From, $FromName, $Subject, $AddressTo, $cc){
include(“class.phpmailer.php”);
//include(“class.smtp.php”); // optional, gets called from within class.phpmailer.php if not already loaded$mail = new PHPMailer();
$body = “This is where you can put the dynamic content $variables a lot of $variables”
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = “ssl”; // sets the prefix to the servier
$mail->Host = “smtp.gmail.com”; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server$mail->Username = $username; // GMAIL username
$mail->Password = $password; // GMAIL password$mail->AddReplyTo($ReplyTo,”John Doe”);
$mail->From = $From;
$mail->FromName = $FromName;$mail->Subject = $Subject;
//$mail->Body = “Hi,<br>This is the HTML BODY<br>”; //HTML Body
$mail->AltBody = “To view the message, please use an HTML compatible email viewer!”; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap$mail->MsgHTML($body);
$mail->AddAddress($AddressTo, “John Doe”);
$mail->AddCC($cc,”Server”);
$mail->AddAttachment(“images/phpmailer.gif”); // attachment
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo “Mailer Error: ” . $mail->ErrorInfo;
} else {
echo “Message sent!”;
}
}
This is the actual code that I am using, the variables are defined for its self as you can see. Save this file into something that you are familiar with. When you call this function use this.
$variable = $_REQUEST[‘textboxname’];
……and the rest of your dynamic content
require(“fileofsomethingthatyouknow.php”);
mailer($receivedate, $firstname, $lastname, $mname, $email, $msg, “youraccount@gmail.com”,”PASSWORD”,”FROM@YOURDOMAIN.com”,”YOUR@YOURDOMAIN.COM”,”Name”,”SUBJECT “, “TOYOURACCOUNT@ACCOUNT.COM”,”CCyouraccount@gmail.com”);
just fill in the blanks and you’re done.
The red code the: $body; is where you will place the body of the email, TABLE or DIV whatever you want name it. Just put it there, and several tests to see if your email is neat and beautiful.
I hope this helps on some of your projects. Happy CODING!
Leave a reply to mobifishki Cancel reply