Creating sendmail email template using checkboxes.

Hi there,

I have a page devised on my site which creates an email which is then sent using PHP's sendmail function.  The email consists of a standard "header" text, and also a standard "footer" text.  

I have also got four checkboxes on the page, which, depending on whether they are clicked or not, will insert four chunks of text in the middle part of the email.

Initially I have been trying the following...  The required elements are $msg_header and $msg_footer and the optional elements are $msg_check1, $msg_check2, $msg_check3 and $msg_check4 - I tried a few "show if checkbox = true" snippets, but I just couldn't do it!  Help please...!


$email = "destination@email.com";
$from_header = "From: Our Site Name <info@oursitename.com>";
$subject = "Our Subject";
$msg_header = "Dear " . $firstname . ",\n\n
This is the header text!\n\n";
$msg_check1 = "This is the optional text for checkbox 1\n\n\";
$msg_check2 = "This is the optional text for checkbox 2\n\n\";
$msg_check3 = "This is the optional text for checkbox 3\n\n\";
$msg_check4 = "This is the optional text for checkbox 4\n\n\";
$msg_footer = "This footer!\n\n";
$message = $msg_check1 . $msg_check2 . $msg_check3 . $msg_check4"; 
(mail($email,$subject,$message,$from_header));

Open in new window

SamDavisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SamDavisAuthor Commented:
By the way.... the variables of the actual checkboxes are...

$checkbox1
$checkbox2
$checkbox3
$checkbox4

So, I was trying some kind of...

if ($checkbox1 == 0) ( print "$msg_check1" }

But that didn't work.
0
Kshitij AhujaTechnology DeveloperCommented:
1. if ($checkbox1 == 0) ( print "$msg_check1" }

If this is the real chunk of code u are using in test...the print should end with a semi colon.

2. (mail($email,$subject,$message,$from_header));
This is from the snippet of code you provided with question. Why are you enclosing the mail function in brackets?
0
SamDavisAuthor Commented:
re: Point 1 - I haven't used this technique, but it's something that I thought might be required to achieve my goal, but it doesn't seem to work.

re: Point 2 - this seems to make no difference to the end result - the emails will still send - I have just seen numerous sendmail snippets of code across the web enclosing the mail function in brackets, so therefore I have followed suit.

Still cannot figure this out.

0
Artysystem administratorCommented:
Ensure that you are using correct variable names and values for checkboxes: http://www.echoecho.com/htmlforms09.htm

In your case it should be something like:
<input type="checkbox" name="checkbox1" value="1"> text1 <br>
<input type="checkbox" name="checkbox2" value="1" checked> text2 <br>
<input type="checkbox" name="checkbox3" value="1"> text3

If you are using POST submit method to submit and your PHP is 5.x, you should use something like:

$email = "destination@email.com";
$from_header = "From: Our Site Name <info@oursitename.com>";
$subject = "Our Subject";
$msg_header = "Dear " . $firstname . ",\n\n
This is the header text!\n\n";
$msg_check1 = "This is the optional text for checkbox 1\n\n\";
$msg_check2 = "This is the optional text for checkbox 2\n\n\";
$msg_check3 = "This is the optional text for checkbox 3\n\n\";
$msg_check4 = "This is the optional text for checkbox 4\n\n\";
$msg_footer = "This footer!\n\n";
$message = $msg_header;
if ($_POST["checkbox1"] == "1") { $message = $message . $msg_check1 };
if ($_POST["checkbox2"] == "1") { $message = $message . $msg_check2 };
if ($_POST["checkbox3"] == "1") { $message = $message . $msg_check3 };
if ($_POST["checkbox4"] == "1") { $message = $message . $msg_check4 };
$message = $message . $msg_footer;

mail($email,$subject,$message,$from_header);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SamDavisAuthor Commented:
Thanks Nopius, did a great job.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Servers

From novice to tech pro — start learning today.