inserting data and images in an email message variable

17 posts by 3 authors in: Forums > CMS Builder
Last Post: November 15, 2012   (RSS)

Re: [gkornbluth] inserting data and images in an email message variable

Hi Jerry,

You could try using CMS Builders mail function to see if that makes a difference. Below is an example of a basic implementation:

$message = 'This is a test message';
$mailArray = array(
'to' => 'example@example.com',
'from' => 'example@example.com',
'subject' => 'This is a subject',
'html' => $message
);
$errors = sendMessage($mailArray);


Also if you use this function in CMS Builder 2.17 it will log your messages for you if you have the feature enabled.

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - November 15, 2012 - edited: November 15, 2012

Hi Greg,

Thanks for the tip about the mail function (didn’t remember that there was one). That seems to have fixed the formatting and exclamation point issues I had.

Two Small issues left...

1) When looping through record list, the email for the last record in the record list always comes up blank. I don’t have any idea how to fix that (except for inserting a dummy record, which is not really a fix, just a quick workaround).

2) I can’t get a variable to display inside the subject line using the $mailArray.

The $where variable is defined much earlier in the page as the name of the exhibition. It renders "Your submission to the $where Exhibition has been Juried" in the email subject line.

Here’s the code I’m using to send the emails.
$the_from = "exhibition-submissions@artistsofpalmbeachcounty.org";
$the_subject = "Your submission to the $where Exhibition has been Juried";
$the_to = $record['email'];
$mailArray = array(
'to' => '$the_to',
'from' => '$the_from',
'subject' => "$the_subject",
'html' => $message
);
$errors = sendMessage($mailArray);


You’re the best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] inserting data and images in an email message variable

Hi Jerry,

I'm not sure what's causing the first point, could you post the latest version of your code?

I think the where variable not being converted because you are putting quotation marks around the variable in the $mailArray function, which makes PHP convert the entire variable to a string and not process any variables in it. Try this instead:

$the_from = "exhibition-submissions@artistsofpalmbeachcounty.org";
$the_subject = "Your submission to the $where Exhibition has been Juried";
$the_to = $record['email'];
$mailArray = array(
'to' => $the_to,
'from' => $the_from,
'subject' => $the_subject,
'html' => $message
);
$errors = sendMessage($mailArray);


Thanks
Greg Thomas







PHP Programmer - interactivetools.com
Hi Greg,

removing the quotation marks was a good idea, but didn't work. Neither did using either single or double quotes around:
$the_subject = "Your submission to the $where Exhibition has been Juried";

The entire file is attached.

I hope I don't feel too silly after these issues are solved.

Thanks again,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] inserting data and images in an email message variable

Hi Jerry,

I think I've found the problems, I've amended them on exhibition_upload3.php and attached it to this post.

1) I notice that you have the e-mail that is being sent to yourself before $message variable. So I think on the first e-mail it was sending the message variable wasn't set, but on all subsequent loops it was using the message from the previous loop (I hope that makes sense!?). So I've moved the sendMesage function to be after the message variable.

2)On the e-mail that was going to yourself you had single quotes and not double quotes on the subject, and PHP only reconizes variables in strings with double quotes.

Let me know if this doesn't fix the problems.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com
Thanks Greg,

A second and more experienced pair of eyes always helps in the end.

I took out the second mailArray (left over by mistake) and that seems to have solved both issues.

I knew I'd be embarrassed in the end...

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php