Home > Web > Dynamic Content for PHP MAILER – for GMAIL

Dynamic Content for PHP MAILER – for GMAIL

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 your 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 a several tests to see if your email is neat and beautiful.

Hope this helps on some of your projects. Happy CODING!

  1. September 23, 2008 at 6:53 am | #1

    Супер ржал целый день.

  2. enrizuu
    October 4, 2008 at 12:24 am | #2

    I am not quite sure I understand clearly but I believe this is not spam anyway!
    Please translate this in more generic readable format.

    Thanks dude!

  3. November 10, 2008 at 12:41 pm | #3

    Здесь можно установить тему на телефон.

  4. November 17, 2008 at 2:27 pm | #4

    О! Тема :)

  5. November 18, 2008 at 8:59 am | #5

    Весьма!

  6. February 6, 2009 at 6:25 pm | #6

    О! Тема :)

  7. February 9, 2009 at 9:39 am | #7

    О! Тема :)

  8. February 12, 2009 at 1:05 pm | #8

    О! Тема :)

  1. No trackbacks yet.